[英]Arquillian in-container test: only first test passes, others fail
I wrote some container tests to see if the correct exceptions are thrown. 我编写了一些容器测试,以查看是否抛出了正确的异常。 If I run each test in the test class separately they work, but if I run all tests inside the class at once, only the first test passes and all others fail.
如果我分别在测试类中运行每个测试,那么它们可以工作,但是如果我一次在该类中运行所有测试,则只有第一个测试通过,其他所有测试都将失败。 The error is:
java.lang.AssertionError: Expected exception: de.paylax.exception.user.KYCValidationAlreadyAskedException
. 错误为:
java.lang.AssertionError: Expected exception: de.paylax.exception.user.KYCValidationAlreadyAskedException
。
I run the tests from eclipse (JUnit4 Runner). 我从eclipse(JUnit4 Runner)运行测试。
This is my test Class: 这是我的测试班:
@RunWith(Arquillian.class)
public class PaymentBoundaryExceptionTests extends InContainerTest {
@Inject
private PaymentBoundary paymentBoundary;
@Inject
private ContractControl contractControl;
@Inject
private UserControl userControl;
/***********************************************************************
* Exception Tests
*/
/**
* Check if Exception is thrown when wrong payout amount
*/
@Test(expected = WrongTransactionAmountException.class)
@UsingDataSet({ "datasets/common/common.yml", "datasets/payments/payments.yml" })
public void PaymentBoundary_WrongPayOutAmount_WrongTransactionAmountException() {
ContractEntity contractEntity = contractControl.findContractByContractCode("goodsContract");
paymentBoundary.createPayout(100, 20, 10, contractEntity.getPayee(), contractEntity, "test");
}
/**
* Check if Exception is thrown when wrong transfer amount
*/
@Test(expected = WrongTransactionAmountException.class)
@UsingDataSet({ "datasets/common/common.yml", "datasets/payments/payments.yml" })
public void PaymentBoundary_WrongTransferAmount_WrongTransactionAmountException() {
ContractEntity contractEntity = contractControl.findContractByContractCode("goodsContract");
paymentBoundary.transferFromWalletToWallet(contractEntity.getPayer(), contractEntity.getPayee(), 100, 20, 10,
contractEntity);
}
// .... more tests here
I am guessing that there is something wrong with my test setup. 我猜我的测试设置有问题。 Here is my InContainer-Test:
这是我的InContainer-Test:
public abstract class InContainerTest {
/**
* Create the Web Archive.
*
* @return the web archive
*/
@Deployment(testable = true)
public static final WebArchive createDeployment() {
// loads the pom configuration
File[] dependencies = Maven.resolver().loadPomFromFile("pom.xml").importRuntimeDependencies().resolve()
.withTransitivity().asFile();
// loads the mockito framework for testing
File mockito = Maven.resolver().loadPomFromFile("pom.xml").resolve("org.mockito:mockito-all:1.10.19")
.withTransitivity().asSingleFile();
// adds the package for MyProject pointing to the RestMyProject api
WebArchive war = ShrinkWrap.create(WebArchive.class).addPackages(true, "de.MyProject").addClass(RestMyProject.class)
.addAsLibraries(dependencies).addAsLibraries(mockito)
// adds the test perisistence xml configuration
.addAsResource("test-persistence.xml", "META-INF/persistence.xml")
// adds the test beans.xml and the log4j2.xml
.addAsResource("test-beans.xml", "META-INF/beans.xml").addAsResource("log4j2.xml", "log4j2.xml")
// adds the MyProjectMapping.xml
.addAsResource("MyProjectMapping.xml", "MyProjectMapping.xml")
// EMail Templates
.addAsResource("HTMLEmailTemplate/admin-info.html", "HTMLEmailTemplate/admin-info.html")
// SQL
.addAsResource("datasets/scripts/truncate-users.sql", "datasets/scripts/truncate-users.sql")
.addAsResource("datasets/scripts/autoincrement-users.sql", "datasets/scripts/autoincrement-users.sql")
.addAsResource("datasets/scripts/contracts.sql", "datasets/scripts/contracts.sql");
;
return war;
}
}
Also, is it wrong that I am using @UsingDataSet()
on each test rather than once on the class? 另外,我在每个测试中都使用
@UsingDataSet()
而不是在类中使用一次是错误的吗? For my understanding, this way the tables get reset and seeded for each @Test
. 以我的理解,这样就可以为每个
@Test
重置表并为种子设置种子。
Regarding @UsingDataSet you can set at class level. 关于@UsingDataSet,可以在类级别进行设置。 APE takes care of removing data after each test.
APE会在每次测试后删除数据。 You can modify this behaviour but IIRC works in this way
您可以修改此行为,但是IIRC以这种方式工作
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.