简体   繁体   English

从命令行运行JUnit Test suite

[英]Run JUnit Test suite from command line

How do I run a Junit 4.8.1 Test suite from command line ? 如何从命令行运行Junit 4.8.1测试套件? Also I want to use the categories introduces with JUnit 4.8 , is there a way where I can specify from command line the category which I want to run. 另外我想使用JUnit 4.8引入的类别,有没有一种方法可以从命令行指定我想要运行的类别。

Using java run JUnitCore class (also see here ). 使用java运行JUnitCore类(另见这里 )。

Categories are supposed to be used with test suites with @RunWith(Categories.class) , @IncludeCategory and @ExcludeCategory . 类别应该与@RunWith(Categories.class)@ExcludeCategory @IncludeCategory@ExcludeCategory测试套件一起使用。 I am not aware of any dynamic way to use categories to run tests but I'd like to know of such it it exists. 我不知道使用类别来运行测试的任何动态方法,但我想知道它存在的这种情况。 You can have pre-defined test suites for certain categories to run them. 您可以为某些类别预先定义测试套件来运行它们。

没有办法(从4.8开始)从命令行指定类别。

I can suggest two approaches: 1. Create Ant file with junit target and then invoke this target from commend line. 我可以建议两种方法:1。使用junit目标创建Ant文件,然后从commend行调用此目标。 2. Implement test suite class, in it in some class with main() method. 2.使用main()方法在一些类中实现测试套件类。 So you will be able to run it. 所以你将能够运行它。

In 4.10, we do this: 在4.10中,我们这样做:

mvn verify -p(your profiles) -Dit.test=(SuiteClass)

where SuiteClass is an empty class (no methods or fields) that is annotated with @RunWith(Categories.class) and @Suite.SuiteClasses({FooIT.class, BarIT.class, ...}) . 其中SuiteClass是一个使用@RunWith(Categories.class)@Suite.SuiteClasses({FooIT.class, BarIT.class, ...})注释的空类(无方法或字段@Suite.SuiteClasses({FooIT.class, BarIT.class, ...}) FooIT and BarIT are the integration tests. FooITBarIT是集成测试。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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