简体   繁体   English

如何从gradle项目中的命令行覆盖集成测试中的属性?

[英]How can I override a property in an integration test from the command line in a gradle project?

Say, for example, you have a data source specified in a properties file and you want to override it in CI. 例如,假设您在属性文件中指定了数据源,并且希望在CI中覆盖它。 If I do something like: 如果我这样做:

gradle -DdataSource.user=fred clean integrationTest

...will this be visible to the running JVM of the test or will this go only to Gradle? ...这对于正在运行的测试JVM是可见的,还是仅仅是Gradle? What's the right way to do this? 这样做的正确方法是什么? I'm actually writing a test right now to figure this out, but somebody else can have the cheddar if the answer shows up here first. 我现在正在编写一个测试来解决这个问题,但是如果答案首先出现在这里,其他人可以拥有切达干酪。

No, just passing it this way won't make this variable avalable in your tests. 不,只是以这种方式传递它不会使这个变量在你的测试中有用。 You have configure your test tasks to make them populate this property into tests. 您已配置测试任务以使其将此属性填充到测试中。

This could be done once for all the test tasks this way 这可以通过这种方式对所有测试任务执行一次

tasks.withType(Test) { systemProperty 'datasource.user', System.getProperty('datasource.user', 'defaultisername') }

Or if you have a number of variable to populate, then pass them all once, like so 或者,如果要填充一些变量,则将它们全部传递一次,就像这样

test {
    options {
        systemProperties(System.getProperties())
    }
}

暂无
暂无

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

相关问题 如何从命令行使用gradle运行测试套件 - How can I run a test suite using gradle from the command line 如何从命令行将 VM arguments 传递给 gradle? - How can I pass VM arguments to gradle from command line? 如何从命令行(Ubuntu 18.04,失败:错误的插件选项格式)构建这个 gradle 项目 (KotlinParcelize)? - How can I build this gradle project (KotlinParcelize) from the command line (Ubuntu 18.04, fail: Wrong plugin option format)? 有谁知道如何将gradle属性传递到单元测试并在命令行上覆盖它们? - Does anyone know how to pass gradle properties to unit test and override them on command line? 如何从命令行在 Java Gradle 项目中运行 main 方法? - How do I run a main method in a Java Gradle project from command line? 如何从命令行运行springmvc + gradle项目? - How to run a springmvc+gradle project from command line? 如何在命令行上覆盖typeafe配置列表值? - How can I override a typesafe config list value on the command line? 如何通过在 gradle 命令行上传递 version 属性来设置 project.version? - How to set project.version by passing version property on gradle command line? 如何从命令行覆盖 distributionManagement? - How do I override distributionManagement from the command line? 无法将参数从命令行传递到Maven项目。 我想传递可以运行测试的服务器URL - Not able to pass parameter from command line to maven project. I want to pass server url on which I can run my test
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM