Java: JUnit common error resolution
- foreword
- 一、org.junit.runners.model.InvalidTestClassError: Invalid test class 'com.software.ApplicationTests': 1 Method contextLoads() should be public
- 二、Runner org.junit.internal.runners.ErrorReportingRunner (used on class com.software.ApplicationTests) does not support filtering and will therefore be run completely.
foreword
This article records the problems that occur during method testing with JUnit, and provides detailed solutions
一、org.junit.runners.model.InvalidTestClassError: Invalid test class ‘com.software.ApplicationTests’: 1 Method contextLoads() should be public
Solution: According to the tips given, add public modification to the contextLoads() method
二、Runner org.junit.internal.runners.ErrorReportingRunner (used on class com.software.ApplicationTests) does not support filtering and will therefore be run completely.
The reason for the error: the junit version is wrong. Your junit version in the pom is inconsistent with that of @Test. Just select the version under maven when @Test. Don’t choose the one with api, and SpringJUnit4ClassRunner only supports version 4.12 and above
Solution: Replace the imported org.junit.jupiter.api.Test; this package with org.junit.Test;
replace it with: