This week's book giveaway is in the General Computing forum.
We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line!
See this thread for details.
The moose likes Testing and the fly likes JUnit Testing - for a complete Java Project. Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Engineering » Testing
Reply Bookmark "JUnit Testing - for a complete Java Project." Watch "JUnit Testing - for a complete Java Project." New topic
Author

JUnit Testing - for a complete Java Project.

Sreenivas Mangasandra
Greenhorn

Joined: Dec 16, 2004
Posts: 10
Hallo Everybody,

I am new to JUnit and i have tried testing the sample testcases given with JUnit from Ant.

How can one apply Test cases for a complete project, i.e. a set of java source files, is it like i have to include a source directory in JUnit or how ?

what i understood till now is:

1. A build.xml file is used to execute test using Ant.
2. *Test.java with classes of them.
3. JUnit jar files.

So would that mean for me to test a project (set of java files) i need to write seperate *Test.java files to test them or can we just have one common component for any project.

It would be nice if any one can clear my question
with an example. Thanks.



Sreenivas Mangasandra.


Regards,<br /> <br />Sreenivas
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
JUnit tests are unit tests. That means that each of your JUnit classes (classes that extend junit.framework.TestCase) is generally responsible for testing one class and one class only.

For example, let's say I have a small application that consists of three classes: Square, Circle, and Triangle. For these classes, I might have written test classes named TestSquare, TestCircle, TestTriangle, TestResizingTriangle, TestSkewingSquare, and so forth. Most of the time, it's one test class per one production class, but not always. Sometimes it just makes sense to split your unit tests for a given class into separate source files because they're testing different aspects of the production code.


Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
Jared Richardson
author
Ranch Hand

Joined: Jun 22, 2005
Posts: 113
Originally posted by Lasse Koskela:
[QB]JUnit tests are unit tests. That means that each of your JUnit classes (classes that extend junit.framework.TestCase) is generally responsible for testing one class and one class only.

QB]


Don't forget that you can use the JUnit testing framework to do much more than just unit testing though. We use it for unit testing, functional testing as well as integration testing.

The same attributes that make it attractive for unit testing (lightweight, portable, fast) also make it great uppper level testing framework as well.


Check out <b>Ship It! A Practical Guide to Shipping Software</b><br /> <br /><a href="http://www.pragmaticprogrammer.com/titles/prj/" target="_blank" rel="nofollow">http://www.pragmaticprogrammer.com/titles/prj/</a>
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
Originally posted by Jared Richardson:
Don't forget that you can use the JUnit testing framework to do much more than just unit testing though. We use it for unit testing, functional testing as well as integration testing.

That's true. We're also using JUnit for our integration tests. Yet, sometimes it would somehow seem better from a learning perspective to not be able to do that--just so that people realize that there's a difference between unit tests and integration tests even though they're both written as JUnit test cases...
Jared Richardson
author
Ranch Hand

Joined: Jun 22, 2005
Posts: 113
Michael Feathers blogged on the topic this week.

A Set of Unit Testing Rules
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: JUnit Testing - for a complete Java Project.
 
Similar Threads
packing classpath errors
JUnit in Action questions
How to create Java document from java files?
Emma and JUnit
ANT - JUNIT