Unit Test, unittest
- Private methods must be called for exposed methods. When exposed methods are tested, private methods are also tested. If not, is there a problem with code refactoring?
- The purpose of unit testing is to ensure that all programs that reference this Code are not affected when you modify the reusable code. The private method cannot be referenced by other classes, therefore, it is not necessary to use unit tests to ensure its correctness.
- But it is based on the following principles. You should not have any methods designed to be private from the very beginning, because each program should be generated under the drive of unit test, and the test cannot drive a private method. So where does the private method come from? It can only be reconstructed. Therefore, the private method does not need to be tested because it is the product of refactoring, and refactoring does not change the behavior that the program can observe. Since the behavior does not change, the test naturally does not need any changes, so no new tests are required for the private method.
How to Create a java Unit test
To put it simply, add @ Test before the method with no return value, and then introduce the jar package of junit .. This ide will all have it. Just introduce it directly. The simple code is as follows: Then run as junit test to run it.
Public class IntegerTest {
@ Test
Public void test (){
Integer i1 = new Integer (2 );
Integer i2 = new Integer (2 );
Integer i3 = 35;
Integer i4 = 35;
System. out. println (i3 = i4 );
}
}
Hello everyone, who has the java class package unittestjar jar? Please send tao-1939 @ 163com
Official Address: sourceforge.net/projects/junit/
Lower it by yourself