This week's book giveaway is in the Java in General forum.
We're giving away four copies of Think Java: How to Think Like a Computer Scientist and have Allen B. Downey & Chris Mayfield on-line!
See this thread for details.
Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Extending JUnit

 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
J. B. Rainsberger
author
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34378
346
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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)
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Pradeep bhatt
Ranch Hand
Posts: 8927
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are there any JUnit extensions to test mult-threaded applications?
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
author & internet detective
Marshal
Posts: 34378
346
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
author & internet detective
Marshal
Posts: 34378
346
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Probably should mention it is a US law
 
Chris Gastin
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeanne, that was a very interesting read, thanks!
 
Irwin Gee
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeanne - are the Test Case extensions for Section 508 something that you can share?

Thanks in advance.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34378
346
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7466
50
Android Eclipse IDE IntelliJ IDE Java Linux Mac Scala Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34378
346
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Junilu,
I'll send it out tomorrow.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic