This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Testing and the fly likes Designating test category - Functional Tests with JUnit Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » Testing
Bookmark "Designating test category - Functional Tests with JUnit" Watch "Designating test category - Functional Tests with JUnit" New topic
Author

Designating test category - Functional Tests with JUnit

Peter Pascale
Greenhorn

Joined: Jun 18, 2008
Posts: 1
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
internet detective
Marshal

Joined: May 26, 2003
Posts: 30076
    
149

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.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Arup Kumar
Greenhorn

Joined: Jun 19, 2008
Posts: 5
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

Joined: Jun 19, 2008
Posts: 5
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.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Designating test category - Functional Tests with JUnit
 
Similar Threads
For Mr. Cohen: Testing Java vs. testing .NET
JUnit Testing - for a complete Java Project.
[ANT] Can I run a junit test suite in a multi-thread manner?
Should I use TestSuite in Junit 4?
Project directory structure that facilitates all kinds of developer testing