Cannot JUnit test using Spring Cannot JUnit test using Spring spring spring

Cannot JUnit test using Spring


Is that your whole pom? if not you need to include spring-core, as spring-test only has it as an optional dependency

<dependency>  <groupId>org.springframework</groupId>  <artifactId>spring-core</artifactId>  <version>${project.version}</version>  <optional>true</optional></dependency>

What optional means in the context of maven:

Indicates the dependency is optional for use of this library. While the version of the dependency will be taken into account for dependency calculation if the library is used elsewhere, it will not be passed on transitively.

You may need to include other spring libraries depending upon what you end up testing.

I was able to get your test running including the following Spring dependencies along with spring-test:

    <dependency>        <groupId>org.springframework</groupId>        <artifactId>spring-context</artifactId>        <version>3.1.1.RELEASE</version>        <scope>test</scope>    </dependency>    <dependency>        <groupId>org.springframework</groupId>        <artifactId>spring-test</artifactId>        <version>3.1.1.RELEASE</version>        <scope>test</scope>    </dependency>    <dependency>        <groupId>org.springframework</groupId>        <artifactId>spring-beans</artifactId>        <version>3.1.1.RELEASE</version>        <scope>test</scope>    </dependency>    <dependency>        <groupId>org.springframework</groupId>        <artifactId>spring-core</artifactId>        <version>3.1.1.RELEASE</version>        <scope>test</scope>    </dependency>