Run JUnit Test suite from command line

2020-03-19 18:15发布

How do I run a Junit 4.8.1 Test suite from command line ? 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.

4条回答
该账号已被封号
2楼-- · 2020-03-19 18:27

I can suggest two approaches: 1. Create Ant file with junit target and then invoke this target from commend line. 2. Implement test suite class, in it in some class with main() method. So you will be able to run it.

查看更多
Rolldiameter
3楼-- · 2020-03-19 18:31

There is no way (as of 4.8) to specify categories from the command line.

查看更多
Bombasti
4楼-- · 2020-03-19 18:42

Using java run JUnitCore class (also see here).

Categories are supposed to be used with test suites with @RunWith(Categories.class) , @IncludeCategory and @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.

查看更多
Deceive 欺骗
5楼-- · 2020-03-19 18:43

In 4.10, we do this:

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, ...}). FooIT and BarIT are the integration tests.

查看更多
登录 后发表回答