When you write JUnit single measurements using spring, you can use the annotations to start and configure a jar package for spring Pom to introduce the
<properties> <junit.version>4.9</junit.version> <slf4j.version>1.6.4</slf4j.ver Sion> <log4j.version>1.2.17</log4j.version> <spring.version>4.1.3.release</spring. version> </properties> <dependencies> <dependency> <groupid>junit</gro Upid> <artifactId>junit</artifactId> <version>${junit.version}</version>
;
<scope>test</scope> </dependency> <!--log component--> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> <v ersion>${slf4j.version}</version> </dependency> <dependency> <groupid& Gt;org.slf4j</groupid> <artifactId>slf4j-log4j12</artifactId> <version>${s Lf4j.version}</version> </dependency> <dependency> <groupid>log4j</groupid>
; <artifactId>log4j</artifactId> <version>${log4j.version}</version> </depend ency> <!--Spring--> <dependency> <groupid>org.springframework</group Id> <artifactId>spring-context</artifactId> <version>${spring.version}</ve rsion> </dependency> <dependency> <groupid>org.springframework</groupi D> <artifactId>spring-core</artifactId> <version>${spring.version}</versio n> </dependency> <dependency> <groupid>org.springframework</groupid>
;
<artifactId>spring-beans</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> <version>${spring.version}</version> & Lt;/dependency> <dependency> <groupId>org.springframework</groupId> & Lt;artifactid>spring-web</artifactid> <version>${spring.version}</version> </d ependency> <dependency> <groupId>org.springframework</groupId> <ar Tifactid>spring-jdbc</artifactid> <version>${spring.version}</version> </depen dency> <dependency> <groupId>org.springframework</groupId> <ar Tifactid>spring-test</artifactid> <version>${spring.version}</version> </d Ependency> </dePendencies>
testing base Classes and JUnit tests
Package com.simple.test;
Import Org.junit.runner.RunWith;
Import org.springframework.test.context.ContextConfiguration;
Import Org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
/**
* Test class base class, load Spring
* @author fengyuxili
*
/@RunWith (springjunit4classrunner.class)
@ Contextconfiguration ({
"Classpath:spring/applicationcontext.xml",
"classpath:spring/ Springmvc-config.xml "
}) public
abstract class Basetest {
}
package com.simple.test;
Import Org.junit.Test;
Import org.springframework.beans.factory.annotation.Autowired;
Import Com.simple.service.CommonService;
/**
* Spring Test class
* @author fengyuxili
* */public
class Springtest extends basetest{
@ autowired
private Commonservice commonservice;
@Test public
void Testcommonservice () {
commonservice.commoncheck ();
}
}