• Post Reply Bookmark Topic Watch Topic
  • New Topic

junit test in general  RSS feed

 
mike foulk
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Need help with JUnit tests.
Can some one show me a few assert test examples, I'm so clueless with these things, like assertEquals, and assertNotNull.(please show me how in a beginner level example)

things I need to test now are: getting things With SQL and storing them into a collection and returning them.
 
Peter Chase
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why not STFW before asking?

I Googled for "junit test example" and got some good-looking articles on the first page. Searching for "junit test example SQL" revealed some DB-specific stuff.

Also, did you try www.junit.org ?
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's a typical thing:

You can also give a comment that will be displayed on failure only:

The other assert methods are very similar. assertTrue takes a boolean and fails on false. assertNotNull takes any object and fails on null.

It's ok for test methods to throw exception. If an exception indicates an error just let it fly.

If you WANT the test subject to throw an exception:

STRONG RECOMMENDATION: The Bowling Game Kata is a great example of using JUnit at the center of the programming task. Look for whitepapers and tutorials at JUnit.org, too.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!