简体   繁体   English

JUnit测试类的主要方法是什么?

[英]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.

相关问题 跨所有 Junit 测试类的使用方法 - Use method across all Junit Test classes JUnit-在主方法中将属性文件作为命令行arg传递,并在每个测试套件的每个测试类中使用该文件 - JUnit - pass a properties file as a command line arg in a main method and use the file in each of the test classes in each test suite 解释此junit测试中的fail()方法的作用 - Explain what this fail() method does in this junit test 如何将主方法类转换为Junit测试类? - How to turn main method class to Junit test class? 在使用 Junit 测试使用 FileInputStream 的主要方法时使用 assertThrows - Using assertThrows while using Junit test for main method using FileInputStream Java-使用JUnit测试公共静态void主方法 - Java - test a public static void main method with JUnit 如何使用 JUnit 5 测试 Java 中的 Public Static Void Main 方法? - How to test the Public Static Void Main method in Java using JUnit 5? 是否可以从junit测试的主要方法中获取变量? - Is it possible to obtain variables in main method from junit test? 多次测试主要方法-Java JUnit - Test Main Method Multiple Times- Java JUnit 如何在我的 JUnit 测试中应用我的主文件中的方法? - How to apply a method from my main file in my JUnit test?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM