Java: JUnit common error resolution


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

insert image description here

二、Runner org.junit.internal.runners.ErrorReportingRunner (used on class com.software.ApplicationTests) does not support filtering and will therefore be run completely.

insert image description here

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;
insert image description here
replace it with:
insert image description here

Guess you like

Origin blog.csdn.net/qq_46119575/article/details/130386042