[英]What goes in the main method of JUnit test classes?
What is supposed to go in the main method for JUnit test classes? JUnit测试类的主要方法应该包含哪些内容? 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. 我专注于从Notepad ++学习它,但是注意到Netbeans使用JUnit甚至没有在类中使用main方法。
JUnit tests are not executed as standalone Java applications so they don't need the main
method. JUnit测试不会作为独立的Java应用程序执行,因此它们不需要
main
方法。 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. JUnit测试由测试运行程序执行, 测试运行程序使用其他机制来确定如何设置和执行测试,在现代版本的JUnit中,它将成为注释。
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). 没有什么可以阻止您使用包含一些引导代码的
main
方法创建JUnit测试的,但是由于其他解决方案的丰富性,通常无法做到这一点,因为其他解决方案可以轻松地运行多个测试并汇总结果并将其提供给进一步的构建步骤(Maven +例如Surefure)。
Side note: don't harm your learning process by using Notepad++ for Java development. 旁注:通过使用Notepad ++进行Java开发,不会损害您的学习过程。 Any proper Java-enabled IDE that will offer autocomplete and context-sensitive help will be infinitely better than a text editor.
任何能够提供自动完成和上下文相关帮助的适当的启用Java的IDE都将比文本编辑器好得多。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.