当前页面: 开发资料首页 → JBuilder 专题 → JBuilder2005单元测试之捆绑多个用例
摘要: JBuilder2005单元测试之捆绑多个用例 目前我们只为Subsection类生成了一个测试用例,在这节里,我们按照前述的方法,通过Test Case向导为StringUtils类创建一个测试用例...
1. package chapter25; 2. import junit.framework.*; 3. public class TestStringUtils extends TestCase 4. { 5. public void testString2Array() { 6. String str1 = null, str2 = "", str3 = "a", str4 = "a,b,c",str5 = ",a,b,"; 7. String[] arr1 = null, arr2 = {""}, arr3 = {"a"}, arr4 = {"a", "b", "c"}, 8. arr5 = {"", "a", "b", ""}, trimArr5 = {"a", "b"}; 9. 10. assertNull(StringUtils.string2Array(str1, ',', false)); 11. assertTrue(isArrayEquals(arr1, StringUtils.string2Array(str1, ',', false))); 12. assertTrue(isArrayEquals(arr2, StringUtils.string2Array(str2, ',', false))); 13. assertTrue(isArrayEquals(arr3, StringUtils.string2Array(str3, ',', false))); 14. assertTrue(isArrayEquals(arr4, StringUtils.string2Array(str4, ',', false))); 15. assertTrue(isArrayEquals(arr5, StringUtils.string2Array(str5, ',', false))); 16. assertTrue(isArrayEquals(trimArr5, StringUtils.string2Array(str5, ',', true))); 17. assertFalse(isArrayEquals(StringUtils.string2Array(str5, ',', false), 18. StringUtils.string2Array(str5, ',', true))); 19. } 20. 21. //判断两个字符数组是否相等 22. private boolean isArrayEquals(String[] arr1, String[] arr2) { 23. if (arr1 == null || arr2 == null) { 24. if (arr1 == null && arr2 == null) { 25. return true; 26. } else { 27. return false; 28. } 29. } else if (arr1.length != arr2.length) { 30. return false; 31. } else { 32. for (int i = 0; i < arr1.length; i++) { 33. if (!arr1[i].equals(arr2[i])) { 34. return false; 35. } 36. } 37. return true; 38. } 39. } 40. } |
![]() 图 错误!文档中没有指定样式的文字。选择套件中捆绑的测试用例 |
![]() 图 错误!文档中没有指定样式的文字。指定测试套件类名 |
1. package chapter25; 2. import junit.framework.*; 3. public class TestSuite1 4. extends TestCase 5. { 6. public TestSuite1(String s) { 7. super(s); 8. } 9. 10. public static Test suite() { 11. TestSuite suite = new TestSuite(); 12. suite.addTestSuite(chapter25.TestStringUtils.class); 13. suite.addTestSuite(chapter25.TestSubsection.class); 14. return suite; 15. } 16. } |
suite.addTest(suite_1) |
suite.addTest(new TestSubsection ("testGetValue")) |
![]() 图 错误!文档中没有指定样式的文字。用测试套件运行组合运行多个测试用例 |