-
Notifications
You must be signed in to change notification settings - Fork 134
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Test context reading 'wrong' application properties file #534
Comments
Same problem here. If there is any workaround please share. For my case, I use DBRider to test database. It will delete tables in database before or after start test case. From this problem cause dev's database tables will be deleted instead of test's database. For my workaround is run command line |
It might have a better solution to this issue. For now, you can try the following workaround:
Here is an example: {
"run": {
"default": "todo-app-java-on-azure",
"items": [
{
"name": "todo-app-java-on-azure",
"projectName": "todo-app-java-on-azure",
"workingDirectory": "c:\\Users\\sheche\\Desktop\\todo-app-java-on-azure-master",
"args": [
],
"vmargs": [],
"env": {
"spring.config.location": "classpath:/target/test-classes/"
},
"preLaunchTask": ""
}
]
},
// ...
} Please let me know if this could help with your problem. Thanks |
Hi @jdneo, I have followed the steps you mention and it's working now 👍. Thanks for your help!! :) |
@jdneo, please document this either on readme or wiki page. |
I'm doing now further testing and seems that the workaround is fixing the issue only partially. With the referred configuration Following the Spring Boot 2.1.0-RELEASE documentation (that is my project framework version) I have tried adding additional properties to env specification such as |
@pablo-parra Thanks, I'll look into it. |
Sorry for the late reply. After some investigation, I found out that it is because the classpath generated from the Java Language Server will put the I'll figure out if there is any solution to correct the order. |
Fixed in #629 and will be released within |
Having same problem, waiting for next release! |
Same problem here! |
issue is still happening in version 0.30.0 |
@EdgarArguelles Could you share a sample project? |
@jdneo This bug is reproducible with Gradle, but not with Maven. I tried a small Spring project with both Gradle and Maven, but was unable to reproduce it with Maven. The project can be found here: https://github.com/fvclaus/vscode-java-test-application-properties. I have two
If I execute it in vscode, the test fails: I believe it is because the order of the main and test classpath is flipped:
As a workaround, I currently use:
|
@fvclaus, it's a known issue that the classpath resolved by Gradle(Buildship) is wrong. In the future we will consider to add a feature that delegate the test execution to Gradle (that will make sure the result is the same as running from command line) See: #1045 (comment) |
The wrong application.properties file is used so the tests try to connect to a PostgreSQL DB. When executing the tests on the command line with gradle there is no issue. Bug and workaround: microsoft/vscode-java-test#534 (comment)
The Gradle Test Delegation (both run and debug) has supported now. To use this feature, you need to install the latest Test Runner for Java and Gradle for Java extension. To delegate the tests to Gradle, you can set the default testing profile in Testing explorer: If you do not want to change the default testing profile, you can trigger an one-time execution via: |
In a Spring Boot sample project using a MySQL db as main data source and H2 as test data source, when launching the test using Java Test Runner extension the application properties file read by the app is the one located in the "main" package instead the one located in the "test" package. Due to that all the test fail as are not finding the expected infrastructure.
The test of the project are working fine in Eclipse.
The text was updated successfully, but these errors were encountered: