简体   繁体   English

我需要在启动时将application-test.properties路径设为100%唯一,以进行Spring Boot单元测试

[英]I need to make an application-test.properties path 100% unique at startup for a spring boot unit test

I need to make an application-test.properties path 100% unique at startup for a spring boot unit test. 对于Spring Boot单元测试,我需要在启动时将application-test.properties路径设为100%唯一。

I was thinking I could use the current time in milliseconds, or a generated UUID, but I don't know how I would do that from within a properties file. 我当时以为可以使用当前时间(以毫秒为单位)或生成的UUID,但我不知道如何从属性文件中执行该操作。

I'm using some of the jenkins variables plus some defaults for local testing to get it closer, but it's not 100% certain due to the way the pipeline was set up. 我正在使用一些jenkins变量以及一些默认值进行局部测试,以使其更接近,但由于管道的设置方式,它不确定100%。

Current application-test.properties: 当前的应用程序test.properties:

data.path=tmp/Bob/test-${BRANCH_NAME:local}-${BUILD_ID:local}/source

I'm looking for something like this: 我正在寻找这样的东西:

data.path=tmp/Bob/test-${BRANCH_NAME:local}-${BUILD_ID:local}-${UUID.randomUUID().toString())}/source

or 要么

data.path=tmp/Bob/test-${BRANCH_NAME:local}-${BUILD_ID:local}-${System.currentTimeMillis()}/source

or something similar. 或类似的东西。

Note: I can't mess with the pipeline at this time, or I'd just create a variable for this purpose. 注意:目前我不能弄乱管道,或者我只是为此目的创建一个变量。

Spring boot provides a random property source . Spring Boot提供了一个随机属性源 This lets you inject random ints, longs, and even UUIDs into your properties. 这样,您就可以向属性中注入随机的整数,长整型甚至是UUID。

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

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