Arquillian 容器内测试:只有第一个测试通过,其他测试失败

Arquillian in-container test: only first test passes, others fail

我写了一些容器测试来查看是否抛出了正确的异常。如果我 运行 测试 class 中的每个测试分别工作,但如果我 运行 一次 class 内的所有测试,只有第一个测试通过,所有其他测试都失败.错误是:java.lang.AssertionError: Expected exception: de.paylax.exception.user.KYCValidationAlreadyAskedException

我 运行 来自 eclipse (JUnit4 Runner) 的测试。

这是我的测试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

我猜我的测试设置有问题。 这是我的 InContainer 测试:

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;
    }
}

此外,我在每次测试中都使用 @UsingDataSet() 而不是在 class 中使用一次,这是错误的吗?据我了解,通过这种方式可以为每个 @Test.

重置和播种表格

关于@UsingDataSet,您可以在class级别设置。 APE 负责在每次测试后删除数据。您可以修改此行为,但 IIRC 以这种方式工作