question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
BoykoAlexcommented, Jun 16, 2022

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

0reactions
BoykoAlexcommented, Jun 17, 2022
Read more comments on GitHub >

github_iconTop Results From Across the Web

Reduce amount of or remove @Autowired annotations In ...
Reduce amount of or remove @Autowired annotations In Spring Junit 5 test · What do you want to achieve by removing those? Maybe...
Read more >
Spring Tools 4.15.1 released
... (Spring Boot) fixed: VScode quick fix should not suggest removing @Autowired annotation from JUnit tests (#786); (Eclipse) fixed: Not ...
Read more >
Spring Boot support in Visual Studio Code
Navigate to your pom.xml file and right-click to select Add starters.... A dropdown will show the dependencies you already have beginning with a...
Read more >
Java: How to fix Spring @Autowired annotation not working ...
When a new instance is created not by Spring but by for example manually calling a constructor, the instance of the class will...
Read more >
Disable and suppress inspections | IntelliJ IDEA Documentation
For example in Java, if you suppress an inspection for a class, a method, or a field, the IDE adds the @SuppressWarnings annotation....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found