简体   繁体   中英

What goes in the main method of JUnit test classes?

What is supposed to go in the main method for JUnit test classes? This is one example I use but don't really understand it and am curious to other options?

public static void main(String[] args) {
        junit.textui.TestRunner.run(new JUnit4TestAdapter(InflectionPointTest.class));
}

I'm focusing on learning it from Notepad++ but noticed Netbeans uses JUnit without even having a main method in the class.

JUnit tests are not executed as standalone Java applications so they don't need the main method. JUnit tests are executed by test runners which use other mechanisms for figuring out which how to set up and perform the tests, in modern versions of JUnit it will be the annotations.

Nothing stops you from creating a JUnit test with a main method that contains some bootstrapping code but this is not commonly done due to abundance of other solutions that make it easy to run multiple tests and aggregate results and feed them into further build steps (Maven+Surefure, for instance).


Side note: don't harm your learning process by using Notepad++ for Java development. Any proper Java-enabled IDE that will offer autocomplete and context-sensitive help will be infinitely better than a text editor.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM