• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Designating test category - Functional Tests with JUnit

 
Peter Pascale
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We're trying to implement a JUnit-based solution that would allow us to designate a test as being a functional test, to be run as part of a functional test build on our integration server.

Basically we need a way to tell unit tests apart from functional tests. We would rather not segregate the functional tests in a different directory structure. Instead we'd like something annotation-based if possible.

The current thinking call for introduction of a custom Runner that
identifies functional test based on a custom annotation. Then we can
co-mingle unit and functional tests, not relying on directory
segregation.

This must be a common problem, yet I don't see a common solution. And even if we do go through the trouble of writing a custom Runner, how does one specify the use of that Runner in an ant <junit> execution?
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34073
335
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Peter,
Welcome to JavaRanch!

I assume you are using JUnit 4 since you are talking about annotations. If so, this extension supports a category annotation. TestNG does as well, but that's not JUnit.
 
Arup Kumar
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey Peter, we are trying to achieve the same functionality.
I was having two approaches.
1.)Using AnnotationRunner class, and getting
Description d=annoRunner.getDescription();and based on the description which I assumed will reflect the Annotation tag, extract the Category and Run'em sequentially.

2.) I wanted to register the Categories as Listner's and execute it using a sample like..
JUnitCore core= new JUnitCore();
//Result result= new JUnitCore().runMain(args);
//RingingListener ring=new RingingListener();
 
Arup Kumar
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Currently its possible to add

@Category ("A") to a junit test.
and get to run the test case based on Category A, with the following lines of code, which is adapted from the CategoryFilterTest class of Junit-ext 0.24.
JUnitCore core = new JUnitCore();
Request req = Request.aClass(ACategoryTest.class);
Runner r=req.getRunner();
setCategoryValue("A");
core.run(req.filterWith(new CategoryFilter(getCategoryValue())));

We would like to ask if someone is working on a way to assign multiple
categories
like
@Category("A", "B", "C")
//Above line is just a conceptual representation, not possible syntactically.
to add such kind of a category to a junit test and easily get those multiple categories.

Also, it would be nice to have a functionality in Ant to specify the
category of test cases we want to run in the <junit> task.
If this has not been done, I guess we may take the initiative to
provide this.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic