Before executing JUnit unit testing, modify environment variables

The same code can be connected to different databases for JUnit testing without changing the configuration file.

The difference between non-development, testing and production environments. Instead, I stand here and hit wherever I point!

To avoid reinventing the wheel, refer to the blog post:

Use junit&spring to modify the system's environment variables to solve docker program testing problems_junit environment variables_fly-iot's blog-CSDN blog

Main keywords:

Maven dependencies:

<dependency>
        <groupId>com.github.stefanbirkner</groupId>
        <artifactId>system-rules</artifactId>
        <version>1.16.1</version>
        <scope>test</scope>
</dependency>
 

Java类:EnvironmentVariables

The following blog post is for reference only and has not been tested.

How to set environment variables or system properties in Spring tests? - SegmentFault Sifou

Guess you like

Origin blog.csdn.net/u011453631/article/details/132766506