Database Cleanup after every junit test cases with http calls

為{幸葍}努か 提交于 2019-12-04 15:52:49

you could use @Before and @After methods to perform this activity.

Note that @Before will be executed before every test and @After will be executed after every Test .So @Before you should insert the records , now you know which records have been inserted , delete only them in @After

If you want to add few different records for each test then use try .... finally

like below

class Test{
     @Before
        public void setUp(){
             // insert x Records 
        }


      @After
        public void tearDown(){
             // delete x Records 
        }


         @Test
                public void someTest() throws Exception {
              //  ... insert few records 
                try{
                doSomething();
              }finally{
            //  deleteRecordsInserted for this test.
             }

            }

}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!