Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

doubt in junit... first time user

 
amitabh mehra
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2187
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic