spring-projects / spring-projects/spring-tools

application.properties in main and test source folder

Open
#317 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

for: eclipse status: needs-investigation type: bug
Dominant language
Java
Stars
983
Forks
240
Avg merge
7d 1h
Merged PRs (30d)
7

Description

An application.properties file is stored in src/main/resources as well as in src/test/resources defining the same property with a different value. Further a JUnit test exists which prints the value of that property (assigned to a variable using the Value annotation).

If the JUnit test is called by Run As -> JUnit Test the value of the main application.properties is printed. Instead, if the test is called with "gradlew clean test", the value of the test application.properties is printed.

If an application.properties/yml (or bootstrap.properties/yml if Spring Cloud Config is used) file exists both in main and test source folder, always and only the latter file should be resolved for a JUnit test.

Tested with Eclipse 4.10.0, Spring Tools 4.3.0, Gradle 4.10.3 and Spring Boot 1.5.21.

As a workaround src/test/resources/application.properties can be moved to src/test/resources/config/application.properties to print the value of the test application.properties. But then other properties from the main application.properties are also available, i.e. test application.properties does not replace main application.properties.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the issue with application.properties in src/main/resources and src/test/resources, using the JUnit test through Run As → JUnit Test and gradlew clean test. Compare the resolved values, including the application.properties/yml and bootstrap.properties/yml cases; done means the test-resource configuration is consistently resolved for a JUnit test without losing the intended main properties.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring-boot
Domain
developer-experience, testing
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.