小学测试作业

身体一天不如一天
211506368霍金池 211606359戴俊涵
1.设计思路
对小学不同年级,根据输入情况进行junit4测试。定义一个待测试的类,并且定义两个变量,一个用于存放参数,一个用于存放期待的结果。
2.部分单元测试代码
@Test
public void testMathFactory1() {
//一年级
GradeOneMath one = (GradeOneMath) MathExam211506368.MathFactory(1);
assertNotNull(one);
assertTrue(one.getClass().equals(GradeOneMath.class));
//二年级
GradeTwoMath two = (GradeTwoMath) MathExam211506368.MathFactory(2);
assertNotNull(two);
assertTrue(two.getClass().equals(GradeTwoMath.class));
//三年级
GradeThreeMath three = (GradeThreeMath) MathExam211506368.MathFactory(3);
assertNotNull(three);
assertTrue(three.getClass().equals(GradeThreeMath.class));
}
创建testMathFactory1分别对应不同年级,调用不同方法测试。
3.遇到的问题
我们写的方法中出现了除数为0的情况
Failures:测试失败,比如我们在方法改成下面的形式 public void testAdd() {
2 int z=new T().add(2, 4);
3 //判断z==6,以往的assert
4 assertEquals(6, z);
5 assertTrue(z<3);
6 // int a=8/0;
7 }

4.单元测试覆盖率
这里我真的是试了不知道多少次了,好吧。我绝望了.....

5.结构优化

6.性能调优

7.优化方案
删减部分代码,并对for循环的优化,每次在i++的时候都会重新计算一次args.length,优化之后只会计算一次。

The last
第一次通宵交作业了,然而更多的确是绝望,已经尽力了。这里想感谢一下我宿舍的小伙伴的热心帮助,心累TT。

猜你喜欢

转载自www.cnblogs.com/MISAYAHAN/p/9727356.html