与一个JAR文件进行OpenLiberty集成测试

huangapple go评论56阅读模式
英文:

openliberty integration testing with a jar file

问题

我正在尝试按照这里的指南学习运行集成测试,这正是我们在功能上所需要的。我们组织中的设置方式是,在项目的这个阶段,我们生成一个jar文件,而不是war文件。然后,另一个与我们无关的DevOps项目会从这个jar文件中构建war文件,使用各种特定于环境的属性,并部署它。

问题是,我们如何告诉OpenLiberty最好以编程的方式将jar文件转换为war文件以部署二进制文件,然后在集成测试中使用它?例如,运行下面的测试:链接

英文:

I am trying to follow the guide here to learn to run integration tests which is exactly what we need functionality wise.
https://github.com/OpenLiberty/guide-jpa-intro/blob/prod/finish/backendServices

In our org the way things are setup is that we produce a jar file instead of a war file at this phase of the project. Then another unrelated devops project which we do not control over builds the war file from this jar file with various env specific properties and deploys it.

https://github.com/OpenLiberty/guide-jpa-intro/blob/prod/finish/backendServices/pom.xml

    <groupId>io.openliberty.guides</groupId>
    <artifactId>backendServices</artifactId>
    **<packaging>jar</packaging>**
    <version>1.0-SNAPSHOT</version>

The question is how do we tell openliberty ideally programmatically to turn the jar file into a war file to deploy the binary and then use it for integration testing ?
for e.g. run the below test https://github.com/OpenLiberty/guide-jpa-intro/blob/prod/finish/backendServices/src/test/java/it/io/openliberty/guides/event/EventEntityIT.java

答案1

得分: 2

你可以使用一个单独的测试 WAR 模块,该模块将你的 JAR 模块作为依赖项。

这个 WAR 模块可以包括:

  • 用于集成测试服务器的Liberty配置 (src/main/liberty/config/server.xml)
  • 集成测试的 Java 文件 (**IT.java)
  • liberty-maven-plugin 的配置,用于在集成测试期间安装Liberty测试服务器并部署你的应用程序
  • failsafe 插件的配置,用于集成测试

这不会阻止你通过其他DevOps流程单独构建另一个WAR(例如生产环境),该流程会忽略这个测试WAR模块。

另一种方法

如果你认为这样更好组织你的整个项目,也可以在JAR模块中保留集成测试源代码**IT.java,同时使用单独的测试WAR模块。然后,你将要配置failsafe插件来针对测试WAR模块运行集成测试,将应用程序部署到测试Liberty服务器,并且不要配置failsafe插件在JAR模块构建的上下文中运行集成测试。

不过我认为将集成测试源代码包含在WAR模块中可能更好,因为它使用了与Liberty服务器紧密耦合的端点(例如主机/端口)。你可以使用一个单一的“多模块”Maven项目将所有代码组织到一个单一的源代码仓库(Git)中,可能使用Maven的“配置文件”来控制是构建和执行集成测试逻辑,还是只构建JAR依赖项(供其他DevOps流程使用)。

英文:

You could use a separate test WAR module which uses your JAR module as a dependency.

This WAR module could include:

  • Liberty config for your integration test server (src/main/liberty/config/server.xml)
  • The integration test Java files (**IT.java)
  • The liberty-maven-plugin config to assist in installing the Liberty test server and deploying your application during IT
  • The failsafe plugin config for integration testing

This shouldn't prevent you from separately building another WAR (e.g. production) through some other DevOps process which ignores this test WAR.

ALTERNATIVE

It would also be possible to use the separate test WAR module while keeping the integration test source **IT.java within the JAR module, if you feel that is a better organization of your overall project. You would want then to configure the failsafe plugin to run IT against the test WAR module deploying the app to the test Liberty server and NOT configure the failsafe plugin to run IT in the context of the JAR module build.

I think it might be better though to include the integration test source within the WAR module since it's using endpoints (e.g. host/port) which are tightly-coupled to the Liberty server. You could use a single "multi-module" Maven project to allow all of the code to be grouped into a single source repository (Git), possibly using Maven "profiles" to control whether to build and execute the IT logic or just to build the JAR dependency (for use by your other DevOps process).

huangapple
  • 本文由 发表于 2023年7月10日 19:34:37
  • 转载请务必保留本文链接:https://go.coder-hub.com/76653329.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定