Unit Test, unittest

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.