• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

doubt in junit... first time user

 
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 2187
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic