Home » Java » java – Failed to load ApplicationContext after adding @SpringBootTest annotation-Exceptionshub

java – Failed to load ApplicationContext after adding @SpringBootTest annotation-Exceptionshub

Posted by: admin February 25, 2020 Leave a comment

Questions:

I wanted to unit test a controller. I get an error java.lang.IllegalStateException: Failed to load ApplicationContext

After I added this annotation @SpringBootTest(webEnvironment = RANDOM_PORT, classes = {App.class}) I got the error

Here is the defined class:

@RunWith(SpringRunner.class)
@ActiveProfiles("test")
@SpringBootTest(webEnvironment = RANDOM_PORT, classes = {App.class})
public class ControllerTest {
}

Any idea on how to solve this?

I don’t have any applicationContext.xml in my project

Edit:
This is the App Class

@SpringBootApplication
@EnableCaching
public class App {
    public static void main(String[] args) {
        boolean assertionsEnabled = false;
        boolean skippedOverAssertFalse = false;
        try {
            skippedOverAssertFalse = true;
        } catch (Throwable e) {
            assertionsEnabled = true;
        }
        if (!assertionsEnabled || skippedOverAssertFalse) {
            System.err.println("FATAL ERROR: Utils.myAssert does not work as intended which might bring the system to an illegal state. Aborting.");
            System.exit(1);
        }
        // ]]
        SpringApplication.run(App.class, args);
    }
}
How to&Answers: