aspose file tools*
The moose likes Testing and the fly likes Good JUnit Tutorial? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Testing
Bookmark "Good JUnit Tutorial?" Watch "Good JUnit Tutorial?" New topic
Author

Good JUnit Tutorial?

Tom Blough
Ranch Hand

Joined: Jul 31, 2003
Posts: 263
Are there any good JUnit tutorials on the Web suitable for a beginner? What's the recommended "beginners" book?
Thanks


Tom Blough<br /> <blockquote><font size="1" face="Verdana, Arial">quote:</font><hr>Cum catapultae proscriptae erunt tum soli proscripti catapultas habebunt.<hr></blockquote>
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8919

http://quilt.sourceforge.net/tutorials/junit.html
Good book
JUnit in Action
You may win the book this week. Good luck!


Groovy
Tom Blough
Ranch Hand

Joined: Jul 31, 2003
Posts: 263
Pradeep, I get a 404 error on that link, as well as the tutorials directory.
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
The link should be valid. It seems that quilt.sourceforge.net is down.


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

Joined: May 10, 2002
Posts: 341
The "Unit Testing in Java: How Tests Drive the Code" is a good book to beginning unit testing.
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30913
    
158

Tom,
While it's not a tutorial, the bowling example provides a nice overview. It follows two programmers through the exercise of using Junit to write a program using test driven development.


[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
Jason Menard
Sheriff

Joined: Nov 09, 2000
Posts: 6450
Just my two cents, but I would be careful about confusing test driven development (TDD, aka test-first design), a development methodology, with JUnit, a framework. Creating good unit tests does not require that TDD principles be used.
A couple of JUnit tutorials worth checking out are JUnitTest Infected: Programmers Love Writing Tests and JUnit: A Starter Guide.
The article Jeanne linked to is an excellent overview of test-driven development and pair programming. It's definitely worth a read. For a detailed look at TDD, you may want to check out Evolution of Test and Code Via Test-First Design (pdf).
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30913
    
158

Jason,
I agree about not confusing the two. Some (but not all) of the junit tutorials include TDD. And even more of the articles on TDD include pair programming.
Tom Blough
Ranch Hand

Joined: Jul 31, 2003
Posts: 263
Originally posted by Jason Menard:
Just my two cents, but I would be careful about confusing test driven development (TDD, aka test-first design), a development methodology, with JUnit, a framework. Creating good unit tests does not require that TDD principles be used.

That's the problem when you know just enough to cause trouble. I had thought they were mutual predicates. Now it looks like I have to learn TDD just so I know when and when not to apply it.
Thanks for all the responses so far. I'll be palying with some of the tutorials and walk-throughs this weekend.
Tom
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8919

What is the learning curve for Junit?
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
Originally posted by Pradeep Bhat:
What is the learning curve for Junit?

As I answered to someone earlier, it's very easy to get started with JUnit. Reading this article and trying out the examples yourself is a good start and doesn't take long.
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Originally posted by Jason Menard:
Creating good unit tests does not require that TDD principles be used.

Agreed. TDD is more about creating a good design of the production code than about testing. High test coverage is more of a side effect of TDD.


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
Greg Ostravich
Ranch Hand

Joined: Jul 11, 2002
Posts: 112
For what it's worth - I used the tutorials they point you to when you download JUnit and I got it working reasonbly well.
I think the biggest challenge was figuring out how to set-up the part that ran all my tests and how to use it from the Swing GUI.
Now I use it from Ant and that took a little figuring out too.
If you are using Ant, I'd recommend Erik Hatcher and Steve Loughran's Java Development with Ant - also published by Manning. There are examples on how to set-up Ant with JUnit and how to run the reports that the Ant task can generate.
Here's some more JUnit resources:
Scott Davis, the Ex-President of our local Java User Group did a talk on JUnit for our Basic Concepts.
Here's his ZIP file: http://denverjug.org/bc/junit.zip.
Sort of interesting that Patrick Linskey was the featured speaker and he's co-author of Bitter EJB. The other JUnit resource I'm going to point to is Mike Clark, another co-author of Bitter EJB and author of JUnitPerf.
He spoke to our JUG on Bitter EJB but he also gave a great talk on JUnit to the XPDenver user group.
Agile Design and Testing With JUnit was the name of the talk and it was sponsored by Net Objectives.
Here's a link that describes Mike's talk (which was terrific by the way) and here's a link to his notes. He also does Test Driven Design and I believe he talked about that but as others have mentioned, you do not have to do TDD to start using JUnit.
Hope this helped -


Greg Ostravich - SCPJ2
Tom Blough
Ranch Hand

Joined: Jul 31, 2003
Posts: 263
Thanks, Greg. Ant is also on my to-learn list.
Joey Sanchez
Ranch Hand

Joined: Jun 23, 2011
Posts: 86


I think it is a good JUnit tutorial

http://www.google.com/url?sa=t&source=web&cd=1&ved=0CBUQFjAA&url=http%3A%2F%2Fwww.vogella.de%2Farticles%2FJUnit%2Farticle.html&rct=j&q=junit%20tutorial&ei=vbBkTtigNYqGhQeL8cGpCg&usg=AFQjCNHqX26U3fC3isS-kpoFaYdl3kW08Q&sig2=CJI-nJqiXINXc_HRATQ2Zg&cad=rja
Ali Gordon
Ranch Hand

Joined: Apr 30, 2014
Posts: 182



That is vogella's tutorial. It is not good. It only teaches you to copy paste code. It does not explain why Junit is used and how does it help.


My name was Borat Sagdiyev. But the forum does not allow such names.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Good JUnit Tutorial?