aspose file tools*
The moose likes Testing and the fly likes doubt in junit... first time user Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Testing
Bookmark "doubt in junit... first time user" Watch "doubt in junit... first time user" New topic
Author

doubt in junit... first time user

amitabh mehra
Ranch Hand

Joined: Dec 05, 2006
Posts: 98
While going though Spring mvc tutorial at:
spring-mvc-tutorial

I came to use JUnit for testing purpose. This is the first time I am using JUnit.

I have one doubt. In the code for testing, do all methods in the TestClass get executed without any explicit call to them?
In one of the tests, the TestClass had some 6 methods (name starting with 'test...', I guess this is just convention). Since there was no explicit call made to any of these methods, its my guess that JUnit framework will execute all.

Please explain.

Thanks
Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
You can execute JUnit test processes from a command-line or when using an IDE, you can execute from within the IDE.

In both cases, you are executing a test driver which then makes the explicit calls on the test class. The driver is written to explicitly call all of the methods identified with the @Test annotation.
amitabh mehra
Ranch Hand

Joined: Dec 05, 2006
Posts: 98
In my testClass I had 2 test methods: testGetProductList and testSaveProduct.
I tried running the tests through ant build after removing the 'test' from the names of these methods, and I got this:

[junit] Testcase: warning(junit.framework.TestSuite$1): FAILED
[junit] No tests found in springapp.repository.JdbcProductDaoTests
[junit] junit.framework.AssertionFailedError: No tests found in springapp.repository.JdbcProductDaoTests

And originally, i was thinking that this 'test' thing is just a convention (case sensitive!!!).



Thanks Clark
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
In JUnit 3, all public void methods without arguments that start with the "test" prefix are executed as tests.

In JUnit 4, while that old style still is supported, you typically use the @Test annotation to denote test methods.


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
 
 
subject: doubt in junit... first time user