[英]How to run also ignored tests in JUnit 4 from command line?
I would like to run some ignored tests from a java program's main method in JUnit 4. They are ignored because they only insert some data for demonstration purpose. 我想从JUnit 4中Java程序的main方法中运行一些被忽略的测试。它们被忽略是因为它们仅出于演示目的而插入一些数据。
in my main method: 在我的主要方法中:
JUnitCore junit = new JUnitCore();
junit.run(MyClass.class);
However this will not run test classes annotated with @Ignored 但是,这不会运行带有@Ignored注释的测试类
@Ignore("Only for filling system with demo data")
public class MyClass { ... }
In IntelliJ I can run those by right clicking on the class. 在IntelliJ中,我可以通过右键单击该类来运行它们。 How can I run them from the command line / in a main method? 如何从命令行/在main方法中运行它们?
I saw the Runner IgnoredClassRunner but not sure how to use that and if that is the correct Runner/Class. 我看到了Runner IgnoredClassRunner,但不确定如何使用它,以及那是否是正确的Runner / Class。
It turned out this is quite easy achievable with: 事实证明,这很容易实现:
JUnitCore junit = new JUnitCore();
junit.run(new BlockJUnit4ClassRunner(MyClass.class));
I will leave this answer open if anybody comes up with something better, which just prevents IgnoredClassRunner to be invoked for classes annotated with @Ignored 如果有人提出更好的建议,我将保留此答案,这只会阻止对@Ignored注释的类调用IgnoredClassRunner。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.