I've made a simple Maven Spring REST project. (this one: https://spring.io/guides/gs/rest-service/)
Afterwards I made a simple JUnit test using MockMVC to test the REST functionality. In this case: does my code respond to /greeting?
When I run my test (using IntelliJ) I get this IllegalStateException.
How can I resolve this?
You're probably using incompatible versions of spring-test and spring-boot. spring-test calls SpringApplicationContextLoader.getResourceSuffixes (plural form) since v4.1.0.RC2. spring-boot's SpringApplicationContextLoader.getResourceSufffix (singular) throws that exception since v1.3.0.RC1.
You would have to either upgrade to spring-test >= 4.1.0 or downgrade to spring-boot < 1.3.0
Related
I add annotation SpringBootTest on my test class, it works very well in IDE(intellij), but when I run mvn test command, it seems SpringBootTest annotation doesn't work, because I didn't see spring context is initialized from logs and the auto-wired object is null. Does anyone know what might be wrong?
BTW, I use spring-boot 2.7.1
This is maven-surefire-plugin issue, spring boot 2.7.1 use junit5 while the maven-surefire-plugin I used doesn't support junit5. Upgrading maven-surefire-plugin can solve this problem
We have spring-boot application ,when we try to run unit tests it seems that some of the unit tests cases are not picking for execution.
This issue started happening after upgrading spring boot version from 2.3.9 to 2.5.12
We are using java 11,gradle 6.8 and gradle dependency testCompile 'junit:junit:4.12'
Any reason of not picking all the test cases for execution?
Check the Spring Boot 2.4 release notes regarding JUnit 5:
If you do not want to migrate your tests to JUnit 5 and wish to continue using JUnit 4, add a dependency on the Vintage Engine
https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-2.4-Release-Notes#junit-5s-vintage-engine-removed-from-spring-boot-starter-test
Is there something in Maven that will tell me that if I'm using version 1.5.4 of spring-boot then I need at least version Camden.SRX for spring-cloud-starter-parent?
I was getting non-helpful errors that a class was not found as I was using Spring 1.5.4 and Brixton for cloud.
Is there a way to use Maven to find matching/compatible versions?
I use Spring Boot - 1.5.3.Release Version for my project. Simply tested my demo application with Actuator and Dev-tools plugin from spring boot initializer site. (Hence I no longer needed to share my POM, as it is default).When I launch my application and try to hit the metrics End Point URL, I get this 401 Unauthorized status (image given below).
Following Options Tried to Bypass this exception
I excluded the SecurityAutoConfiguration on my main Class.
#SpringBootApplication
#EnableAutoConfiguration(exclude= {org.springframework.boot.autoconfigure.security.SecurityAutoConfiguration.class})
public class MainConfig {
But the above option didn't work.
When I downgrade my Spring-Boot - 1.4.6.RELEASE Version, I didn't get the UnAuthorized Exception. My Application worked like a charm :-)
Questions
Is there any Specific Security Enhancements have been made in the latest release of Spring-Boot (1.5.3.RELEASE Version)?
If at all any enhancements made, let know the community on how to bypass such kind of exceptions?
I also, noticed that when using Spring-boot (1.5.3.RELEASE) it doesn't show any exceptions on startup, even though I have multiple main program in my IDE build path. Is that also an enhancement is spring-boot (1.5.3.RELEASE) version?
Kindly clarify.
From the Spring Boot 1.5 Release Notes:
If you’re upgrading a Spring Boot 1.4 application that doesn’t have dependency on Spring Security and you wish to retain open access to your sensitive endpoints you’ll need to set management.security.enabled to false.
I have a custom JUnit test runner that executes acceptance-level tests using a test specification format specific to my project. The system under test is using Spring Boot and takes advantage of its configuration facility. I'd like the tests to be able to read the same configuration files in the same way. Obviously, using Spring Boot Configuration itself is an answer.
I'd like to just use Spring Boot Configuration as a stand-alone library, but I'm willing to fire up Spring Boot if that's what it takes. I'm not in control of the top-level application - JUnit is. So, I don't know how to start Spring Boot when I get control inside my test runner.
I've looked at extending SpringJunit4ClassRunner but I can't keep it from looking for #Test annotations and failing when it doesn't find any. I've started to look into merging code from SpringJunit4ClassRunner into my custom runner. Before I go too far down that path, I'd appreciate input from the community.
It sounds like you simply want the application running for a standalone webservice testing. This can be done simply by scripting the "java -jar" command to run the spring boot application. However, I would question why you don't want to leverage the testing tools built into spring boot? You can fire up the entire spring boot application and write some very logical looking tests.
For example a rest api test case:
#Test
public void homePage() throwsException () {
mockMvc.perform(get("/readingList"))
.andExpect(status().isOk())
.andExpect(view().name("readingList"))
.andExpect((model().attribute("books", is(empty()))));
}