Why use JUnit test instead of the normal Java Main method to complete the test?

Source: Internet
Author: User

Because in the program, an interface corresponds to an implementation method, and in the interface often defines a number of related methods, so at the time of testing, if all in the main method inside the test, the main method will appear bloated, and it is not easy for other people to test and view the test data, with JUnit Test, a method corresponding to a test method, simple and clear, but also easy for others to view the test method and test data.

If you have more than one method in your class, it is inconvenient to test it with the main method, so if you want to test all the methods, you have to write the test code all in main, or you can test a rewrite once. And more importantly, this will make the test code mixed with running logic code, not canonical.
In a regular Java project (especially the use of a framework such as SSH), almost will not write the main method, write is useless code, will be scolded by the manager ...
Using JUnit is a lot easier, this is unit testing, which method you want to write a corresponding test method, and then run with JUnit. Each method is independent and very flexible. And the test method is generally not written directly in the original class, but a separate test class, so that the test code is completely separate from the logic code.
If you use tools like Maven to manage your projects, the benefits of JUnit are further reflected: you can write a large number of test classes, and then use a simple maven command to automate, think about, all automated testing, and test results automatically generated documents, convenient.
In fact, JUnit is not difficult to learn, with one or two times on the general understanding. I wish you a smooth study.

Why use JUnit test instead of the normal Java Main method to complete the test?

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.