Create global variable in Test Suite accessible by all JUnit Test
Asked Answered
B

0

8

I have a question regarding setting up Junit Test Suite. First of all, I am using JUnit libarary version 4.7.

My problem is to create application context in the test suite then allow all the test suite it is running to be accessible to the application context. I need the application context is because some unit test is using it to populate required data. So I am reusing some class to do the deeds.

The following is my snipplet:

@RunWith(Suite.class)
@SuiteClasses({RestServiceUnitTest.class})
public class IntegrationSuite {

public ApplicationContext appCtx;

@BeforeClass
public static void setUp() {
    System.out.println("setting up in Suite");

    appCtx = new FileSystemXmlApplicationContext("/integrationtest/rest_test_app_ctx.xml" );
}

@AfterClass
public static void tearDown() {
    System.out.println("tearing down in Suite");
    CleanUp cleaner = (CleanUp)appCtx.getBean("cleanup");
    cleaner.clean();

    }

}

I need the appCtx to be accessible to the RestServiceUnitTest class. May I know how is this is done ? Anyone has any idea.

I guess it is pretty similiar to : Test invocation: how to do set up common to all test suites

But I not sure how to access the variable you created in the testsuite class in unittest as the answer is not mentioning it.

Blake answered 12/12, 2013 at 7:32 Comment(1)
Maybe this answer will help you.Silverfish

© 2022 - 2024 — McMap. All rights reserved.