繁体   English   中英

Arquillian容器内测试:只有首先通过测试,其他才通过

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

我编写了一些容器测试,以查看是否抛出了正确的异常。 如果我分别在测试类中运行每个测试,那么它们可以工作,但是如果我一次在该类中运行所有测试,则只有第一个测试通过,其他所有测试都将失败。 错误为: java.lang.AssertionError: Expected exception: de.paylax.exception.user.KYCValidationAlreadyAskedException

我从eclipse(JUnit4 Runner)运行测试。

这是我的测试班:

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

另外,我在每个测试中都使用@UsingDataSet()而不是在类中使用一次是错误的吗? 以我的理解,这样就可以为每个@Test重置表并为种子设置种子。

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM