Skip to content
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

VScode quick fix should not suggest removing @Autowired annotation from JUnit tests #786

Closed
tigerinus opened this issue Jun 15, 2022 · 6 comments
Assignees
Labels
for: eclipse something that is specific for Eclipse for: vscode something that is specific for VSCode status: assigned status: in-progress theme: refactoring type: bug

Comments

@tigerinus
Copy link

tigerinus commented Jun 15, 2022

Describe the bug

After a recent update of Spring Boot extension for VSCode, it starts to suggest removing @Autowired annotation from JUnit tests

image

However, after the annotation is removed, test is unable to get launched:

org.junit.jupiter.api.extension.ParameterResolutionException: No ParameterResolver registered for parameter [org.springframework.test.web.servlet.MockMvc mvc] in constructor [public com.newpathfly.flightsupplier.via.service.SearchServiceIT(org.springframework.test.web.servlet.MockMvc,java.lang.String)].
 at java.util.Optional.orElseGet([Optional.java:267](vscode-file://vscode-app/c:/Users/xiaoh/AppData/Local/Programs/Microsoft%20VS%20Code/resources/app/out/vs/code/electron-browser/workbench/workbench.html))
 at java.util.ArrayList.forEach([ArrayList.java:1259](vscode-file://vscode-app/c:/Users/xiaoh/AppData/Local/Programs/Microsoft%20VS%20Code/resources/app/out/vs/code/electron-browser/workbench/workbench.html))
 at java.util.ArrayList.forEach([ArrayList.java:1259](vscode-file://vscode-app/c:/Users/xiaoh/AppData/Local/Programs/Microsoft%20VS%20Code/resources/app/out/vs/code/electron-browser/workbench/workbench.html))

To Reproduce

Build a simple Spring Boot test in an existing Spring Boot project:

@SpringBootTest
@AutoConfigureMockMvc
class WhateverIT {
    private final MockMvc _mvc;

    public WhateverIT (MockMvc mvc) {
        _mvc = mvc;
    }

    @Test
    void dummyTest() {
    }

Note that @Autowired does not exist.

Then try to launch the test from VSCode

@BoykoAlex
Copy link
Contributor

Yes, agreed. Will get this fixed

@BoykoAlex
Copy link
Contributor

Don't think i have better ideas than skipping the case of a class with @SpringBootTest annotation. Any objections?

@tigerinus
Copy link
Author

Don't think i have better ideas than skipping the case of a class with @SpringBootTest annotation. Any objections?

What's the root cause of the issue?

Would you be able to skip the case of a class with any annotation that @BootstrapWith(SpringBootTestContextBootstrapper.class) in case people have their own annotation versus @SprintBootTest?

@BoykoAlex
Copy link
Contributor

We've added removing @Autowired from the only constructor in class but conditions for this marker and quick fix are buggy.

Yes we can skip class annotated with @BootstrapWith(SpringBootTestContextBootstrapper.class) as well without any problems. Thanks for bringing this up

@BoykoAlex
Copy link
Contributor

The fix is 382d0bb.
We'll be creating another release in a few days from now to include this fix. Once the RC is tested I'll mark it as fixed.

@BoykoAlex
Copy link
Contributor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
for: eclipse something that is specific for Eclipse for: vscode something that is specific for VSCode status: assigned status: in-progress theme: refactoring type: bug
Projects
None yet
Development

No branches or pull requests

3 participants