因为@BeforeClass回调不适用于 arquillian 测试,所以我尝试在@PostConstruct测试的回调中初始化一些字段。部署中有一个beans.xml,我也尝试添加@Startup注释和无参数构造函数,但没有效果。尽管 CDI 正在工作,并且正在为测试的其他领域执行所有注入,但@PostConstruct没有被调用。我错过了什么吗?
我正在Arquillian 1.0.0.Final使用JBoss 7.1.1.Final. 我不是在寻找解决方法 - 我可以使用@Before回调。但这显然不是最理想的,因为我只需要为所有测试初始化一次值。更重要的是,观察到的行为似乎与我对 CDI 的理解相矛盾。
这是我的测试要点:
@RunWith(Arquillian.class)
public class UploadResetterTest {
@Deployment
public static Archive<?> createTestArchive() {
return ShrinkWrap
.create(WebArchive.class, "uploadResetTest.war")
.addPackages(true, "my.package")
.addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml");
}
Map<String, String> predicates = new HashMap<String, String>();
@Inject
Logger log;
@PostConstruct
public void postConstruct() {
log.info("postconstruct");
// here I am trying to fill the map
predicates.put("type", UploadTypes.TALLY.toString());
}
@Test
public void testResetTallies() throws Exception {
// here the map is still empty
predicates.get("type");
}