writing test cases
posted 11 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
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.
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.
posted 11 years ago
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!
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
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!
[OCP 21 book] | [OCP 17 book] | [OCP 11 book] | [OCA 8 book] [OCP 8 book] [Practice tests book] [Blog] [JavaRanch FAQ] [How To Ask Questions] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
| Maybe he went home and went to bed. And took this tiny ad with him: Paul Wheaton's 16th Kickstarter: Gardening playing cards for gardeners and homesteaders https://coderanch.com/t/889615/Paul-Wheaton-Kickstarter-Gardening-playing |











