Bazı web kapsamlarını @BeforeTest
yöntemimde ilkbahar kapsamına kaydetmek istiyorum. Ancak bu noktada bahar içeriğinin hala null
olduğu ortaya çıkıyor.Test bağlamında erişme @BeforeTest
@BeforeMethod
olarak değiştirirseniz, sınama gayet iyi çalışıyor. Bağlam kayıt kodunun her bir test yöntemi için tekrarlanmasını istemediğim için, @BeforeTest
'da içeriğe nasıl erişebileceğimi merak ediyorum.
Kod snippet'larım aşağıdadır. testi çalıştırırken
public class MyTest extends MyBaseTest {
@Test public void someTest() { /*...*/ }
}
@ContextConfiguration(locations="/my-context.xml")
public class MyBaseTest extends AbstractTestNGSpringContextTests {
@BeforeTest public void registerWebScopes() {
ConfigurableBeanFactory factory = (ConfigurableBeanFactory)
this.applicationContext.getAutowireCapableBeanFactory();
factory.registerScope("session", new SessionScope());
factory.registerScope("request", new RequestScope());
}
/* some protected methods here */
}
İşte hata mesajı yok: En BeforeTest yöntemde
FAILED CONFIGURATION: @BeforeTest registerWebScopes java.lang.NullPointerException at my.MyBaseTest.registerWebScopes(MyBaseTest.java:22)
Enjekte edilen üyelerin '@ BeforeTest' ve hatta' @ BeforeSuite 'yöntemlerinde neden kullanılmadığına dair herhangi bir belgenin farkında mısınız? – ecbrodie
10x :) daha sonra, daha sonra, çekirdek sonrası işlemci yazıcısı –