在我的 pom.xml 上,我创建了一些配置文件。在我的 Eclipse 项目中,我选择了与 TestNG 一起运行时必须使用的配置文件。测试必须根据配置文件执行不同的操作。我尝试使用 ${project.activeProfiles[0].id}
,但对我不起作用。
Eclipse 选择的配置文件:
TestNG执行错误:
MVN 命令:
当我运行 mvn help:active-profiles
命令时,结果是:
The following profiles are active:
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
mvn help:all-profiles
命令结果是:
[INFO] Listing Profiles for Project: com.myproject:project:jar:1.0
Profile Id: UAT-Dev-Mt (Active: false , Source: pom)
Profile Id: UAT-Dev-Bg (Active: false , Source: pom)
Profile Id: PROD-Dev-Mt (Active: false , Source: pom)
Profile Id: PROD-Dev-Bg (Active: false , Source: pom)
Profile Id: Acceptance (Active: false , Source: pom)
Profile Id: Regression (Active: false , Source: pom)
Profile Id: CriticalPath (Active: false , Source: pom)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
为什么 Eclipse 上的 TestNG 对我来说无法使用此选定的配置文件和 maven pom 变量?
提前谢谢您。
最佳答案
TestNG Eclipse 插件与 Maven 没有很好的集成,TestNG Eclipse 插件提供的有限功能只是准备好当前 Activity 配置文件的 pom.xml 中定义的系统属性(和/或环境变量)。 其他任何内容(例如个人资料特定目标)根本不会执行。
回到您的案例,如果您只想配置文件管理系统属性,您可以选择一个 Activity 配置文件,然后简单地运行 testng 测试,这些属性将被注入(inject)到运行时 testng 进程。对于其他任何内容,尚不支持。
关于java - 如何在 Eclipse 上通过 testng 执行使用 Maven active-profiles,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44818613/