1

I am trying to run a junit test on my spring boot application. Here is my pom.xml:

<!-- https://mvnrepository.com/artifact/junit/junit -->
<dependency>
    <groupId>junit</groupId>
    <artifactId>junit</artifactId>
    <version>4.11</version>
    <scope>test</scope>
</dependency>


<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter</artifactId>
</dependency>

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-test</artifactId>
    <scope>test</scope>
</dependency>

and then in the test class i have the below code:

import org.junit.runner.RunWith;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.boot.test.SpringApplicationConfiguration;

@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = SeleniumApplication.class)
public class DataExtractorTest {

}

Unfortunatly, in the line

@SpringApplicationConfiguration(classes = SeleniumApplication.class)

it complains with

SpringApplicationConfiguration cannot be resolved to a type

and even when i added the

import org.springframework.boot.test.SpringApplicationConfiguration

it complains with

The import org.springframework.boot.test.SpringApplicationConfiguration cannot be resolved

I have cleaned my project, and updated my maven project several times, even closed the STS and try again but none of them worked.

Jeff
  • 7,767
  • 28
  • 85
  • 138
  • In your pom you should specify the version of the dependancy - IIRC `SpringApplicationConfiguration` was deprecated in version 1.4 – Scary Wombat Aug 10 '17 at 05:23
  • Would you please put the `junit` dependency below the `spring-boot-starter-test` dependency in `pom.xml` and run `mvn clean package -U` and test again. Or simply you can delete the dependent file from maven repositories and try again. – sunkuet02 Aug 10 '17 at 05:23
  • @ScaryWombat so, what is the valid version? – Jeff Aug 10 '17 at 05:25
  • 1
    @KamyarParastesh shall I research that for you? – Scary Wombat Aug 10 '17 at 05:26
  • @ScaryWombat i was confused with your answer. do you mean if i don't specify the version, it would automatically select the same version of `junit`? – Jeff Aug 10 '17 at 06:04
  • 2
    what has junit got to do with it? If you do not specify the version of `org.springframework.boot.test` then what version is it going to use - maybe the latest? Does the latest version contain this class? – Scary Wombat Aug 10 '17 at 06:09

0 Answers0