views:

43

answers:

3

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.

+1  A: 

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.

Andriy Sholokh
+1  A: 

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.

grigory
It's possible to create custom test runner that dynamically selects tests to run based on categories.
grigory
+1  A: 

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

Kent Beck