Win a copy of Cloud Native PatternsE this week in the Cloud forum
or Natural Language Processing in the AI/ML 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
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

writing test cases

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

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: 39392
761
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!
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!