Data loading before the entire test case and destruction after the entire test

I use SpringJUnit4ClassRunnerto run a test case integration. Now I load the data into the HSQL memory for each junit test case in the method @Beforeand destroy it in the method @Afterin the Junit Test class. I need the data to load only once, so that the entire test case is inside the test folder. It should also be destroyed after the completion of the entire test. I use Maven for build, JDK8, Spring 4.2.5, and HSQL in memory.

Please help me achieve this logic.

+4
source share
1 answer

, JUnit - Suite Test

, . .

package com.test;

import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;

@RunWith(Suite.class)
@SuiteClasses({Test1.class, Test2.class})
public class TestSuite {

    @BeforeClass
    public static void setUp() {
         // Set up database
    }

    @AfterClass
    public static void tearDown() {
        // Cleanup codes
    }

}

com.test;

import org.junit.Test;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "classpath:context.xml" })
public class Test1 {
    @Test
    public void test1() {
        System.out.println("test1");
    }

}
+1

Source: https://habr.com/ru/post/1675017/


All Articles