У меня есть простой тестовый класс с использованием junit. К сожалению, он жалуется, когда я хочу запустить тестовый пример.Невозможно создать ApplicationContext с помощью NULL 'contextLoader'. Рассмотрите аннотацию тестового класса с @ContextConfiguration
Вот Maven:
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-test</artifactId>
<version>1.4.3.RELEASE</version>
<scope>test</scope>
</dependency>
, а затем в тестовом классе:
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = RestUploaderApplication.class)
public class RestUploaderApplicationTests {
Station station1;
Station station2;
Content content1;
Content content2;
ContentRepository contentRepo;
StationRepository stationRepo;
@Before
public void createObjects(){
Station station1=new Station("UT","Livii 2");
Station station2=new Station("City Center","Kissing Square");
Content content1=new Content(station1,"BMW","Text","google.com",10,true);
Content content2=new Content(station2,"SWB","Image","swb.com",100,true);
}
@Test
public void insertInstancesTest() {
int size=station1.getContents().size();
assertEquals(1,size);
}}
и, наконец, во время выполнения появляется ошибка:
Exception in thread "main" java.lang.NoSuchMethodError: org.junit.runner.notification.RunNotifier.testAborted(Lorg/junit/runner/Description;Ljava/lang/Throwable;)V
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at [org.springframewor[email protected]67b64c45] to prepare test instance a NULL 'contextLoader'. Consider annotating your test class with @ContextConfiguration.
at org.springframework.util.Assert.notNull(Assert.java:115)