JBuilder2005 unit testing bundled with a number of cases
We only Subsection category generated a test case in this section, in accordance with the aforementioned method, Test Case for the wizard to create a test case StringUtils category code framework and the preparation of test methods, and then tied up the two Test Case In combination with a test suite in the operation.
StringUtils categories selected through File-> New ..-> Test, double-click the icon for the Test Case StringUtils category string2Array () method to create test cases, test cases to accept the default category of TestStringUtils.
Test Case Generation Wizard in the framework of the code to delete the test firmware (because it is the static method, there is no need to use firmware), the deletion of the member variables StringUtils statement setUp () and tearDown () method. And the definition of a category isArrayEquals (), delete the wizard generated testString2Array () method of testing the content of the preparation of their own testing code, with the ultimate code as follows:
Code wrong list! Documents do not specify the format of text. TestStringUtils: StringUtils kind of test case
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. Arr1 String [] = null, arr2 = {""}, arr3 = ( "a"), (arr4 = "a" and "b" and "c"),
8. Arr5 = ( "", "a" and "b", ""), (trimArr5 = "a" and "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 / / array judge whether the same two characters
22. Private boolean isArrayEquals (String [] arr1, arr2 String []) (
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.)
Although the JUnit framework for a number of assertEquals () Heavy methods, but there is no reference to the two string array assertEquals () override, we need to judge their own definition of a string array is the same method: isArrayEquals (), such as section 22 ~ 39 firms indicated.
In testString2Array () method, we provide the most coverage of the string test (special string conversion and its target), as in the 6-8 trip indicated. After calling assertXxx () testing rules. You can also, as a test case in the same TestSubsection run it.
NOTE:
If you file in the content pane TestStringUtils Right-click on the label, found only in the pop-up menu Run Test using "TestSubsection", in the Project-> Project Properties …-> Run-> Run settings page in the cancellation TestSubsection Operation Context Menu settings of the options, otherwise it will run the original TestSubsection test case.
Includes only about 10 categories of small projects may not use the test suite, the only run through the test case individually to complete the test can be, but contains more of a test case for the project, you can take the test suite to great convenience, it is bundled with a number of test cases run to a 100 call and should be a batch-processing effects.
Tags: Number






