Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

junit test in general

 
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.
 
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 ?
 
(instanceof Sidekick)
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.
 
The happiness of your life depends upon the quality of your thoughts -Marcus Aurelius ... think about this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic