optimystix
Member • Feb 13, 2014
Basic JUnit related queries
Hi CEans,
I didn't learn JUnit well enough when I had the time and opportunity and now I am fumbling for answers to simple questions that have cropped up in my mind.
Suppose I want to run JUnit tests on 4 methods - addUser, deleteUser, viewUser, updateUser.
My doubts are-
1. When I run JUnit testcases on these, will these actually affect the data in the database (for both - with and without mock objects)?
for eg-
How can we avoid such scenarios?
I don't even know if my queries are correct. Please help and correct me if I am wrong.
Thanks in advance 😀
I didn't learn JUnit well enough when I had the time and opportunity and now I am fumbling for answers to simple questions that have cropped up in my mind.
Suppose I want to run JUnit tests on 4 methods - addUser, deleteUser, viewUser, updateUser.
My doubts are-
1. When I run JUnit testcases on these, will these actually affect the data in the database (for both - with and without mock objects)?
- if they do, won't it create a problem for other test cases which are dependent on the same data present in the db?
for eg-
@Test public void testViewUser() { String userId = "2"; DummyUser dummyUser = dummyUserDao.viewUser(userId); assertNotNull(dummyUser);Here,say, I am running the test case after a month and user id 2 does not exist in the db anymore, so the test case will fail. To avoid that, I will manually have to check and update such fields every time I want to run such cases.
How can we avoid such scenarios?
I don't even know if my queries are correct. Please help and correct me if I am wrong.
Thanks in advance 😀