wood burning stoves 2.0*
The moose likes Testing and the fly likes Extending JUnit Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Testing
Bookmark "Extending JUnit" Watch "Extending JUnit" New topic
Author

Extending JUnit

Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

How many people use stock JUnit, and how many people have their own local extensions? We have a few, the absolute favorite being a method canRun() in our own TestCase subclass, and a run() method that calls it to decide whether to skip certain tests on certain platforms. I wrote this up in the Journal a while back.

Anyway, I know I could answer this by looking at the book's web site, but does "JUnit Recipes" talk about writing JUnit extensions at all?


[Jess in Action][AskingGoodQuestions]
J. B. Rainsberger
author
Ranch Hand

Joined: Aug 05, 2004
Posts: 87
JUnit Recipes does not provide much about specifically how to extend JUnit. I rarely find it necessary to do so for my testing: I tend just to use the existing test runners and all the prefab extensions (HtmlUnit, XMLUnit, Cactus, ...).

Many of the questions we get on the JUnit Yahoo! group garner suggestions for writing custom test runners, but rarely do we get a question that leads us to consider extending the framework itself.

I consider JUnit's framework to be adequate for my needs, but then, perhaps I'm just not solving hard enough problems.


Author of <a href="http://www.amazon.com/exec/obidos/ASIN/1932394230/ref=jranch-20" target="_blank" rel="nofollow">JUnit Recipes: Practical Methods for Programmer Testing</a>
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Originally posted by Ernest Friedman-Hill:
How many people use stock JUnit, and how many people have their own local extensions?


The only "local extensions" I remember using are project specific assert methods...


... a method canRun() in our own TestCase subclass, and a run() method that calls it to decide whether to skip certain tests on certain platforms. I wrote this up in the Journal a while back.


Well, recipe "4.6 Separate the different kinds of test suites" might be interesting to you...


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30116
    
150

Ernest,
We have several types of minor extensions:
- project specific asserions
- general assertions (for collections and other data structures)
- use of test collector to collects tests by package using reflection
- section 508 test (plugs into each application to test for section 508 compliance)


[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
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
Originally posted by Jeanne Boyarsky:
- section 508 test (plugs into each application to test for section 508 compliance)

Jeanne, I'd love to hear more about this? What's section 508 and what does the test do?


Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8904

Are there any JUnit extensions to test mult-threaded applications?


Groovy
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
Originally posted by Pradeep Bhat:
Are there any JUnit extensions to test mult-threaded applications?

http://today.java.net/pub/a/today/2003/08/06/multithreadedTests.html
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Originally posted by Lasse Koskela:
What's section 508


As far as I can tell, it's an accessibility law: http://www.section508.gov/

what does the test do?


That I would like to know, too!
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30116
    
150

Yes, section 508 is an accessibility law. All applications developed for the federal government are required to meet the 16 provisions. The Department of Health & Human Services has a chart that lists the provisions in a clear way.

There are many free tools that let you run your generated HTML through and highlight your Section 508 violations. But it is quite tedious to do this for every single JSP (and every single display combination for those JSPs) on a regular basis. It is also quite tedious to look at the results of these tools. After a couple of experiences with 508 violations slipping through after we "implemented Section 508", it was time to do something about it. Enter Junit - great for tedious, repeatable activities.

Many of the 508 practices are very programatic. For example, practice a states you must have an alt tag for every image. It's very easy to go through a JSP and check for that. We also check for form labels, table headers/summaries and a couple other things. We check for html and struts tags. Granted junit can't check for everything, but some of the 508 practices (like background colors) need to be checked by hand even after using the 508 tools anyway.

Our Section 508 test class is an abstract junit test case (extends TestCase) that provides tests for some of the provisions. It resides in a library jar with our other common stuff. Each application subclasses this test case and implements the method where we state the web project name. After that, the 508 test loops through the jsp directories and gathers them all. It then uses JBs parameterized test case pattern to run each test for each jsp and report the results as separate tests.

Our Section 508 flags a violation about once a week during heavy development. We run it with our other Junit tests, so it gets run often. So it's definitely keeping our code compliant.

Well this was long. I hope I didn't give you guys too much detail.
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30116
    
150

Probably should mention it is a US law
Chris Gastin
Ranch Hand

Joined: Aug 13, 2002
Posts: 51
I find that the base Junit provides enough functionality to do the base testing. I have used some of the Junit extentions such as Cactus, and Struts Test Case. Both of these are great for testing Struts Actions, and servlets.


Chris Gastin<br />SCJP 1.4<br />SCWCD 1.3
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Jeanne, that was a very interesting read, thanks!
Irwin Gee
Greenhorn

Joined: Aug 30, 2004
Posts: 1
Jeanne - are the Test Case extensions for Section 508 something that you can share?

Thanks in advance.
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30116
    
150

Irwin,
The commercial (non-junit) ones like hisoftware's, and pagescreamer have free versions on the web where you can run an HTML file through.

The junit extension is something I wrote. If you PM me your e-mail address, I can send it to you.
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 4444
    
    5

Originally posted by Jeanne Boyarsky:
The junit extension is something I wrote. If you PM me your e-mail address, I can send it to you.


Jeanne,

Me, too! (firstName at javaranch.com) My current project is for the Ohio Dept of Jobs and Family Services and it's partially federally funded so we have to comply with Section 508.

TIA.

Junilu


Junilu - [How to Ask Questions] [How to Answer Questions]
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30116
    
150

Junilu,
I'll send it out tomorrow.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Extending JUnit
 
Similar Threads
Do you know other testing tool like JUnit ??
hibernate MappingException: duplicate import
new to JUnit
How many people are using Spring Surf?
JUnit Recipes: Practical Methods for Programmer Testing by J.B.Rainsberger, et al