eclipse / buildship

The Eclipse Plug-ins for Gradle project.
530 stars 169 forks source link

test/resources are not the classpath when running unit tests #1221

Open BoykoAlex opened 1 year ago

BoykoAlex commented 1 year ago

Consider the following project https://github.com/BoykoAlex/buildship-test-resources

  1. Clone it and import into eclipse.
  2. Run DemoApplication as Java Application
  3. Note Some port = '2222' in the output in the Console view. This value comes from src/main/resources/application.properties which is on the classpath.
  4. Run DemoApplicationTest and JUnit Test
  5. Note again Some port = '2222' and test failure expecting the value to be 8888 rather than 2222

Note that there is a file src/test/resources/application.properties present with value 8888 that is supposed to end up on the classpath for the test run making the unit test pass and print Some port = '8888' in the output. However, this is not the case.

Executing ./gradlew clean build from the terminal runs successfully which means the test passes with Gradle build. Therefore must be something off with Buildship. Converting this project to a maven project, importing into Eclipse with m2e and running the above works as expected as well.

FieteO commented 1 year ago

This is a long standing issue (that personally annoys me as well): #764

Myslawek commented 7 months ago

This is still an issue. The only workaround seems to have two differently named application.(yml/properties). Like:

Then with use of Spring @ActiveProfiles("test") on Your test class, buildship would pick the right one.