Win a copy of JDBC Workbook this week in the JDBC and Relational Databases forum
or A Day in Code in the A Day in Code 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 ...
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
  • Piet Souris
  • salvin francis
  • fred rosenberger

writing test cases

Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I am new to JUnit and i have been assigned the task of writing the test cases for the given class. I have to do it anyhow. Please help me.
The class is :

The Client is a pojo having following fields:
name, location, address, email, contact person all of which are string.

Client and ClientVo are having the same fields as mentioned above. ClientVO is used to transfer the object from database to UI and vice-versa whereas Client is just a pojo.

Currently i am having a dummy class which provides dummy data for the test cases.

Please can anyone write the test cases for the above methods assuming all packages have been imported correctly.

Your help will be highly appreciated.
author & internet detective
Posts: 39986
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

rahul saxenau wrote:Can anybody please write the JUnit test case for the above method.

We will help you, but not write it for you. CodeRanch is NotACodeMill.

The first thing to decide is whether this is a unit test or an integration test. In a unit test, you use a mock framework like jMock or Mockito. That lets you return anything you want from clientDataService.findAllClients();. Which simplifies testing. In an integration test, you actually have the code call the data service.

Regardless, your first steps will be the same. In programming, it is helpful to start small. Can you:
1) Write a JUnit test with one @Test method that has an empty body?
2) Write a @Before method that constructs an instance of your class and stores it in an instance variable?
3) Have your JUnit test call clientDataService.findAllClients method and store the results in a variable called actual (the test may fail, but that is ok for now)?
4) Have your JUnit test mock out clientDataService?
5) Have your JUnit test assert the size of actual?
6) Have your JUnit test assert the values in actual?

Once you can do this, you can proceed to other tests.

Give it a try and post what you are up to when you get stuck. And welcome to CodeRanch!
    Bookmark Topic Watch Topic
  • New Topic