在测试用例期间部署工件 - JBoss AS

发布于 2024-12-18 11:07:22 字数 240 浏览 1 评论 0原文

我有一个非常具体的测试用例:

  1. 我必须部署 JAR
  2. 做一些测试
  3. 部署另一个 JAR
  4. 做更多测试

JAR 必须按此特定顺序部署(在调用测试方法之前我无法同时部署两者)

你知道吗有什么方法可以在类似 JUnit 的环境中执行这种情况吗? 我知道 1. 绝对可以在 Arquillian 中完成,但我不知道是否有可能在测试方法中执行另一个部署。

I have a very specific test case:

  1. I have to deploy JAR
  2. Do some testing stuff
  3. Deploy another JAR
  4. Do some more testing

JARs have to be deployed in this specific order (I can't deploy both before invocation of the test method)

Do you know any way to perform such scenario in some JUnit-like environment?
I know that 1. can be definitely done in Arquillian but I don't know if there's a possibility of performing another deployment inside the test method.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

春夜浅 2024-12-25 11:07:22

您可以在 Arquillian 中使用 TestMethod 中的 Deployer api 来执行此操作。

首先,您必须定义您的 @Deployment 不由 Arquillian 管理:

@Deployment(name = "X", managed = false)
public static WebArchive manualDeployment() {
    return ShrinkWrap.create(WebArchive.class)....
}

下一步是注入 Deployer:

@ArquillianResource
private Deployer deployer;

然后从您的 @Test 方法中您可以调用:

@Test
public void shouldBeAbleToDeploy() {
    deployer.deploy("X")
}

如果您的部署 X 设置为容器内测试(@Deployment .testable=true(默认行为)),您可以在刚刚部署的部署中执行下一个 @Test 方法。

@Test
public void shouldBeAbleToDeploy() {
    deployer.deploy("X");
}

@Test @OperateOnDeployment("X")
public void shouldNowBeInDeploymentX() {
    // we're now inside X
}

默认情况下,JUnit TestMethods 以随机顺序执行,但 Arquillian JUnit 集成提供了 @InSequence(n) 注释,您可以使用它来强制执行顺序。

@Test @InSequence(1)
public void shouldBeAbleToDeploy() {
    deployer.deploy("X");
}

@Test @InSequence(2) @OperateOnDeployment("X")
public void shouldNowBeInDeploymentX() {
    // we're now inside X
}

You can do this in Arquillian using the Deployer api from within your TestMethod.

First you have to define your @Deployment to not be managed by Arquillian:

@Deployment(name = "X", managed = false)
public static WebArchive manualDeployment() {
    return ShrinkWrap.create(WebArchive.class)....
}

The next step would be to inject a Deployer:

@ArquillianResource
private Deployer deployer;

Then from within your @Test method you can call:

@Test
public void shouldBeAbleToDeploy() {
    deployer.deploy("X")
}

If your deployment X is setup for in-container testing (@Deployment.testable=true (default behavior)), you can have the next @Test method be executed inside the deployment you just deployed.

@Test
public void shouldBeAbleToDeploy() {
    deployer.deploy("X");
}

@Test @OperateOnDeployment("X")
public void shouldNowBeInDeploymentX() {
    // we're now inside X
}

By default JUnit TestMethods are executed in random order, but Arquillian JUnit integration provide a @InSequence(n) annotation you can use to force the order of execution.

@Test @InSequence(1)
public void shouldBeAbleToDeploy() {
    deployer.deploy("X");
}

@Test @InSequence(2) @OperateOnDeployment("X")
public void shouldNowBeInDeploymentX() {
    // we're now inside X
}
空城缀染半城烟沙 2024-12-25 11:07:22

测试方法刚刚执行 - 另外,您必须能够从那里进行部署。如果您已经通过设置阶段测试进行了设置部署工作,那么测试是否有效

Test method is just executed - also, you must be able to deploy from there. I f you already have setup deplying stuff through set up phase testing whether it works from test is easy

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文