0

Each time I create a new project with spring boot 1.5.8, there has an error with test class annotation. When I remove the test class and dependency, project run perfectly.

There was problems with @Test annotation, I fixed that adding a Junit4 library.

There is still problems with @RunWith(SpringRunner.class) and @SpringBootTest annotations which show 'cannot be resolved to a type'. How to fix that?

My Test class:

package io.github.imtilab.games;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

@RunWith(SpringRunner.class)
@SpringBootTest
public class GamesApplicationTests {

    @Test
    public void contextLoads() {
    }

}

And pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>io.github.imtilab</groupId>
<artifactId>games</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>games</name>
<description>Demo project for Spring Boot</description>

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.5.8.RELEASE</version>
    <relativePath /> <!-- lookup parent from repository -->
</parent>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <java.version>1.8</java.version>
</properties>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

    <dependency>
        <groupId>org.apache.derby</groupId>
        <artifactId>derby</artifactId>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>


</project>
  • 2
    That annotations (and transitively JUnit as well) should be provided by `spring-boot-starter-test` dependency. Check if the error occurres with Maven as well (using mvn clean install) or only in Eclipse. If it occurres with Maven check that dependency in your .m2 folder, maybe it is corrupted. – helospark Nov 26 '17 at 18:31
  • I'm using Spring tool suit. If I delete the test dependency and test class, project works fine. I can't run mvn clean install in windows but I cleared maven, didn't work for me. – Muhammad Touhidul Islam Nov 26 '17 at 18:35
  • 1
    You can use Maven on Windows, just install Maven and add it to you PATH system variable. By cleared Maven do you mean deleted the .m2 folder? – helospark Nov 26 '17 at 18:41
  • I deleted .m2 and updated maven project but didn't work. Then installed maven and set path but still not solved and how this installed can take effect on my project, I think STS has auto system for maven .m2 – Muhammad Touhidul Islam Nov 26 '17 at 18:55
  • Okay, I deleted again and created a new project with version 1.5.8 and updated the maven project, then somehow this time errors are gone. Thank you. – Muhammad Touhidul Islam Nov 26 '17 at 19:22

0 Answers0