1 솔루션
대신 사용 TestNG.
@Before*
주석은 TestNG에서 this way으로 동작합니다.
@Before*
으로 주석 된 메소드는 정적이어야합니다. 당신이 그렇게하지 않으려면
@org.testng.annotations.BeforeClass
public void setUpOnce() {
//I'm not static!
}
2 솔루션
, 당신은 an execution listener from Spring (AbstractTestExecutionListener
)를 사용할 수 있습니다.
당신은 다음과 같이 테스트 클래스에 주석을해야합니다 :이 방법으로 CustomTestExecutionListener
을 구현 한 후
@TestExecutionListeners({CustomTestExecutionListener.class})
public class Test {
//Some methods with @Test annotation.
}
과 :
public void beforeTestClass(TestContext testContext) throws Exception {
//Your before goes here.
}
자가 포함 된 하나 개의 파일과 같습니다
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"commonContext.xml" })
@TestExecutionListeners({SimpleTest.class})
public class SimpleTest extends AbstractTestExecutionListener {
@Override
public void beforeTestClass(TestContext testContext) {
System.out.println("In beforeTestClass.");
}
@Test
public void test() {
System.out.println("In test.");
}
}
잘 알려진 다른 프레임 워크에 외부 종속성을 추가 할 수 있습니까? –
@ GrzegorzGórkiewicz : 물론, 당신은 무엇을 제안하고 있습니까? – carlspring
다른 솔루션을 추가했습니다. –