Skip to content

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

Closed

Description

@tigerinus

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

Activity

  1. BoykoAlex commented on Jun 15, 2022

    @BoykoAlex
    Contributor

    Yes, agreed. Will get this fixed

  2. self-assigned this
    on Jun 16, 2022
  3. added this to the 4.15.1.RELEASE milestone on Jun 16, 2022
  4. added
    for: eclipse
    for: vscode
    and removed on Jun 16, 2022
  5. BoykoAlex commented on Jun 16, 2022

    @BoykoAlex
    Contributor

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

  6. tigerinus commented on Jun 16, 2022

    @tigerinus
    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?

  7. BoykoAlex commented on Jun 16, 2022

    @BoykoAlex
    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

  8. BoykoAlex commented on Jun 16, 2022

    @BoykoAlex
    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

for: eclipsefor: vscodestatus: assignedstatus: in-progresstheme: refactoringtype: bug

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions