VScode quick fix should not suggest removing `@Autowired` annotation from JUnit tests
See original GitHub issueDescribe the bug
After a recent update of Spring Boot extension for VSCode, it starts to suggest removing @Autowired
annotation from JUnit tests
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:
- Created a year ago
- Comments:6
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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@tigerinus here is the RC that I’ve tried: https://s3.us-west-1.amazonaws.com/s3-test.spring.io/sts4/vscode-extensions/snapshots/vscode-spring-boot-1.36.0-RC.1.vsix Seemed to work fine there.