CrazyEngineers
  • 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
Howdy guest!
Dear guest, you must be logged-in to participate on CrazyEngineers. We would love to have you as a member of our community. Consider creating an account or login.
Replies
  • Kaustubh Katdare

    AdministratorFeb 13, 2014

    Tagging @#-Link-Snipped-# and @#-Link-Snipped-# .
    Are you sure? This action cannot be undone.
    Cancel
  • Anoop Kumar

    MemberFeb 13, 2014

    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.
    Are you sure? This action cannot be undone.
    Cancel
Home Channels Search Login Register