标签:执行 lis highlight pre port 清单 png 目的 target
掌握基于覆盖理论与基本路径的基本白盒测试方法和实践
运用逻辑覆盖测试的覆盖准则设计被测程序的测试用例,并运行测试用例检查程序的正确与否,给出程序缺陷小结。
根据各位同学自己的被测程序,分别作出各类白盒测试技术的用例设计和相应的Junit脚本。
所有的覆盖的技术:语句覆盖、判定覆盖、条件覆盖、判定/条件覆盖、组合覆盖、路径覆盖,基本路径测试方法。
包括的内容有:
1) 被测原代码
被测源码:http://www.cnblogs.com/zenghongyu/p/6626206.html
2)依据覆盖技术,测试用例列表:
因为被测程序没有退出功能,以回到1作为终点
则基本路径的独立路径为
121
1 2 3 4 5 9 1
1 2 3 4 6 7 9
1 2 3 4 6 8 9
3)相应Junit测试脚本、执行结果
语句测试
package Java_1; import static org.junit.Assert.assertEquals; import org.junit.Test; public class PhoneSaleTestSentence { @Test public void testSentence1() { assertEquals("49.0", PhoneSale.commission("5", "5", "5")); } @Test public void testSentence2() { assertEquals("160.0", PhoneSale.commission("10", "20", "50")); } @Test public void testSentence3() { assertEquals("540.0", PhoneSale.commission("20", "100", "100")); } }
语句测试通过
2、判定覆盖
package Java_1; import static org.junit.Assert.assertEquals; import org.junit.Before; import org.junit.Test; public class PhoneSaleTestJudge { @Before public void setUp() throws Exception { } @Test public void testJudeg1() { assertEquals("-1", PhoneSale.commission("10", "-10", "10")); } @Test public void testJudeg2() { assertEquals("9.8", PhoneSale.commission("1", "1", "1")); } @Test public void testJudeg3() { assertEquals("205.0", PhoneSale.commission("10", "10", "100")); } @Test public void testJudeg4() { assertEquals("460.0", PhoneSale.commission("30", "20", "50")); } }
判定覆盖测试通过
条件覆盖和条件/判定 、基本路径选取测试用例相同 如下
package Java_1; import static org.junit.Assert.assertEquals; import org.junit.Before; import org.junit.Test; public class PhoneSaleTestConditon { @Before public void setUp() throws Exception { } @Test public void testCondition1() { assertEquals("-1", PhoneSale.commission("-10", "-10", "-10")); } @Test public void testCondition2() { assertEquals("100.0", PhoneSale.commission("0", "100", "0")); } @Test public void testCondition3() { assertEquals("205.0", PhoneSale.commission("15", "50", "0")); } @Test public void testCondition4() { assertEquals("840.0", PhoneSale.commission("50", "50", "50")); } }
条件测试用例通过
4,组合用例
package Java_1; import static org.junit.Assert.assertEquals; import org.junit.Before; import org.junit.Test; public class PhoneSaleTestConditon { @Before public void setUp() throws Exception { } @Test public void testCondition1() { assertEquals("-1", PhoneSale.commission("-10", "-10", "-10")); } @Test public void testCondition2() { assertEquals("100.0", PhoneSale.commission("0", "100", "0")); } @Test public void testCondition3() { assertEquals("205.0", PhoneSale.commission("15", "50", "0")); } @Test public void testCondition4() { assertEquals("840.0", PhoneSale.commission("50", "50", "50")); } }
组合覆盖测试用例通过
4)给出测试参数化和打包测试的脚本,并生成执行结果
测试参数化
package Java_1; import static org.junit.Assert.assertEquals; import java.util.Arrays; import java.util.Collection; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; import org.junit.runners.Parameterized.Parameters; @RunWith(Parameterized.class) public class PhoneSaleTest1 { private String ph; private String sh; private String pr; private String result; @Parameters public static Collection<Object[]> data() { return Arrays.asList(new Object[][] { { "5", "5", "5", "49.0" }, { "10", "20", "50", "160.0" }, { "20", "100", "100", "540.0" }, { "10", "-10", "10", "-1" }, { "1", "1", "1", "9.8" }, { "10", "10", "100", "205.0" }, { "30", "20", "50", "460.0" }, { "-10", "-10", "-10", "-1" }, { "0", "100", "0", "100.0" }, { "15", "50", "0", "205.0" }, { "50", "50", "50", "840.0" }, { "10", "10", "-10", "-1" }, { "10", "-10", "10", "-1" }, { "-10", "10", "10", "-1" }, { "10", "-10", "-10", "-1" }, { "-10", "10", "-10", "-1" }, { "-10", "-10", "10", "-1" }, }); } public PhoneSaleTest1(String ph, String sh, String pr, String result) { this.ph = ph; this.sh = sh; this.pr = pr; this.result = result; } @Test public void testCommission() { assertEquals(result, PhoneSale.commission(ph, sh, pr)); } }
打包测试的脚本,并生成执行结果
package Java_1; import org.junit.runner.RunWith; import org.junit.runners.Suite; import org.junit.runners.Suite.SuiteClasses; @RunWith(Suite.class) @SuiteClasses({ PhoneSaleTest1.class, PhoneSaleTestConditon.class, PhoneSaleTestGroup.class, PhoneSaleTestJudge.class, PhoneSaleTestSentence.class }) public class AllTests { }
全部通过
标签:执行 lis highlight pre port 清单 png 目的 target
原文地址:http://www.cnblogs.com/1033YCY/p/6706887.html