File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Testing and the fly likes How to write test case for if condition Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Testing
Bookmark "How to write test case for if condition" Watch "How to write test case for if condition" New topic

How to write test case for if condition

Jenifer Rajakumar
Ranch Hand

Joined: Oct 31, 2013
Posts: 34

Iam very new to junit, iam trying junit at first time so please guide to this will be foundation for me to get concepts about junit.

My code was

This code is having link to private method but simple 2 are 3 steps i want to get idea help me. I tried some little code in that iam getting error so please help me and guide me.

my junit code

my error is

Please help me

Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11778

Jenifer Rajakumar wrote:my error is

That is relatively straightforward - you will find it an easy fix. I'm going to point you to the documentation since it explains it better than I can:

You might want to look at Oracle's Controlling Access to Members of a Class tutorial. Or possibly a better bet (since the first link is a bit terse), the Oracle lesson on Object-Oriented Programming -> Data Access Levels might point you to the easy fix.

The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
Kamal Mettananda
Ranch Hand

Joined: Oct 25, 2005
Posts: 51

Jenifer Rajakumar wrote:My code was my junit code

Just to add to what Andrew he pointed you...

Exception trace has given you a message; Method testGetInitiateSearchEntities should be public , and I believe it is detailed enough.

Also if you look at the getInitiateSearchEntities() and testGetInitiateSearchEntities() methods, first one has public, but not the second one. So always make a practice to read the exception content and see whether you can grab something on how to resolve it.

Kamal Mettananda - SCJP 1.4 (98%)
I agree. Here's the link:
subject: How to write test case for if condition
It's not a secret anymore!