File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Testing and the fly likes NUnit, xUnit or JUnit Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Testing
Bookmark "NUnit, xUnit or JUnit" Watch "NUnit, xUnit or JUnit" New topic

NUnit, xUnit or JUnit

HS Thomas
Ranch Hand

Joined: May 15, 2002
Posts: 3404
Which of these is best to start ?

NUnit has TestFixtures which I believe JUnit doesn't?
Any other limitations/benefits to consider.
Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24199

NUnit is for unit testing on .NET. JUnit is primarily for unit testing J2SE programs. xUnit is a collective terms to refer to all JUnit-like tools; there are many! See

[Jess in Action][AskingGoodQuestions]
Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 33111

Also, JUnit does have "test fixtures." It just doesn't call it that in the code.
A test fixture is the context the test executes in. The objects are created in a setUp method and available during your test.

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
HS Thomas
Ranch Hand

Joined: May 15, 2002
Posts: 3404
Thanks Ernest and Jeanne.
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8927

Is Juint automated? I dont think after checking an example. Looks like some code is required?

Greg Ostravich
Ranch Hand

Joined: Jul 11, 2002
Posts: 112
What do you mean by is JUnit automated?
In the program I used JUnit with, I put JUnit in my Ant build.
Then whenever I did a build, it would compile and test as a part of that build. Is this what you mean?
There are a few different ways to run JUnit.
You can run it through the awt graphical interface (but I don't think anybody uses this anymore) or the swing GUI which I think everybody uses when they use a GUI. When you run the GUI it shows a status bar across the display. When the status bar is done, if it's green it's clean.
If it's red there's a problem. It should tell you the line where your assertion failed.
You can also run your JUnit tests from a textual interface.
You can create reports too from your Ant builds through a junitreport Ant task.
Hope this helped -

Greg Ostravich - SCPJ2
Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 33111

Yes, code is required. The idea is to get your test cases into code form. However, the boilerplate code is always the same - so cut and paste works great. Eclipse's code generation works well too.
Lasse Koskela

Joined: Jan 23, 2002
Posts: 11962
Originally posted by Jeanne Boyarsky:
so cut and paste works great.
Regarding this, I'd like to mention that test code should be kept clean just like the production code. If you don't refactor your test code, think about how difficult it will get to change it after some 2000 tests...

Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
I agree. Here's the link:
subject: NUnit, xUnit or JUnit
It's not a secret anymore!