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)?
  • if they do, won't it create a problem for other test cases which are dependent on the same data present in the db?
2. Manual intervention will be required every time I want to run viewUser or updateUser as the user that I am trying to view or update may not be present due to data changes in the db. Am I right? In this case, it would be extremely cumbersome in large number of test cases, to manually change the values of the dependent items.

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 😀

Replies

  • Kaustubh Katdare
    Kaustubh Katdare
    Tagging @#-Link-Snipped-# and @#-Link-Snipped-# .
  • Anoop Kumar
    Anoop Kumar
    Always load data from properties/resource file.
    Using test data directly in class files, you have compile again.
    I didn't worked on jUnit but, you probably know how to this.
    This #-Link-Snipped-#might help you.

You are reading an archived discussion.

Related Posts

Sony announces its new mirrorless camera A6000 just two months after its previous announcement with a clear intention to gain more shares. Many of the Sony's loyal customers were very...
my project is on the basis of solar based wheel chair , movement of wheel chair canb e controlled by controller, and which type of motors i can prefer the...
i need to know ,how can we detect the leak &fire in industries & give which type of transducers are suitable for both
China’s Yutu (Jade Rabbit) lunar rover has managed to come out of its dormant state successfully after it had suffered a malfunction during a scheduled shutdown procedure. Normally, during the...
Hello all, I am Prajakta Paradkar,married to Mr. Shrirang Kelapure. Discipline: Electronics I had completed my graduation from Nagpur university. I am doing my post graduation(M.E.) from Pune in 'signal...