spring junit 测试示例 maven 搭界
来源:互联网 发布:php极光推送原理 编辑:程序博客网 时间:2024/05/01 11:04
pom.xml
<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>com.mv</groupId>
<artifactId>DemoMV</artifactId>
<version>0.0.1-SNAPSHOT</version>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-context -->
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.1.6.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.aspectj/aspectjtools -->
<!-- https://mvnrepository.com/artifact/aspectj/aspectjrt -->
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>1.5.4</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.aspectj/aspectjweaver -->
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.8.5</version>
</dependency>
<!-- https://mvnrepository.com/artifact/commons-io/commons-io -->
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.3</version>
</dependency>
<!-- https://mvnrepository.com/artifact/javax.annotation/jsr250-api -->
<dependency>
<groupId>javax.annotation</groupId>
<artifactId>jsr250-api</artifactId>
<version>1.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-test -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>4.1.1.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/junit/junit -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-compiler-plugin -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
package com.springtest;
public class TestBean {
private String content;
public TestBean(String content) {
super();
this.content = content;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
}
package com.springtest;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
@Configuration
public class TestConfig {
@Bean
@Profile("dev")
public TestBean devTestBean(){
return new TestBean("from development profile");
}
@Bean
@Profile("prod")
public TestBean prodTestBean(){
return new TestBean("from production profile");
}
}
package com.springtest;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes={TestConfig.class})
@ActiveProfiles("prod")
public class DemoTestConfig {
@Autowired
private TestBean testBean;
@Test
public void prodBeanShouldInject(){
String expected="from production profile";
String actual=testBean.getContent();
Assert.assertEquals(expected, actual);
}
}
- spring junit 测试示例 maven 搭界
- maven搭界 配置
- Maven+spring+junit测试,出…
- maven JUnit测试 注意JUnit,spring,mybatis版本号
- Maven+Spring Batch环境的Spring Junit测试集成
- maven+spring+junit测试程序时时出现NoSuchMethodError错误
- maven+spring+hibernate情况下如何使用junit测试
- maven中的junit测试
- Maven聚合、Maven仓库jar包以及Spring+MyBatis+JUnit+Maven整合测试的搭建过程
- JUnit 测试 Spring
- spring junit 测试
- Spring的Junit测试
- spring junit测试
- spring junit集成测试
- spring junit集成测试
- junit 测试 spring
- Spring与junit测试
- JUnit 测试spring项目
- Hdu 5212 Code【容斥原理】
- nexus的仓库介绍,以及配置远程仓库
- [玩转算法]滑动窗口
- intellj idea将自己常用的文件类型添加到菜单栏中
- Android跳转应用市场评分以及目前国内主要的市场包名
- spring junit 测试示例 maven 搭界
- 深入剖析jsonp跨域原理
- 做好企业流程管理的六个建议
- Maven项目中War包的打包及依赖方式
- 01背包问题
- class _declspec(dllexport) class_name与class _declspec(dllimport) class_name的配套使用
- 小用法,使用awk来对文件随机抽取n行
- maven:调用ant执行build.xml的两种方式
- 轻松学JVM(一)——基本原理