maven 打包前 Junit 测试
1. 在需要打包前测试的项目中添加依赖
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
2.在项目目录 src/test/java 下创建单元测试 Test*.java
package event; import org.junit.Assert;
import org.junit.Test; public class Test2 { @Test
public void test() {
Assert.assertEquals(3, 2);
} }
3.运行 maven test
Results : Failed tests: test(event.Test2): expected:<3> but was:<2>
test(event.Test3): expected:<1> but was:<3> Tests run: 3, Failures: 2, Errors: 0, Skipped: 0
4.当然有时候需要加载配置文件
添加 pom
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.1.9.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>4.1.9.RELEASE</version>
</dependency>
测试
@RunWith(SpringJUnit4ClassRunner.class)
@Transactional
@TransactionConfiguration(transactionManager="transactionManager",defaultRollback=true)
@ContextConfiguration(locations = {"classpath*:applicationContext.xml"})
public class UserServiceTest { private static Logger LOGGER = LoggerFactory.getLogger(UserServiceTest.class); protected long startTime; protected long endTime; @Resource
private UserService userService; @Before
public void before() {
start();
} @After
public void after() {
end();
} @Test
public void saveTest() {
User user = new User();
user.setUserName( "test1" );
user.setUserPassword( "test2" );
int count = userService.save( user );
Assert.assertEquals( 1, count );
} /**
* 记录 开始运行时间
*
* @return
*/
protected long start() {
this.startTime = System.currentTimeMillis();
return startTime;
} /**
* 记录 结束运行时间
*
* @return
*/
protected long end() {
this.endTime = System.currentTimeMillis();
this.log();
return endTime;
} /**
* 输出记录
*/
protected void log() {
String text = "\n开始时间 : " + this.startTime + "\n结束时间 : " + this.endTime + "\n执行时间 : " + (this.endTime - this.startTime);
LOGGER.debug(text);
} }
maven 打包前 Junit 测试的更多相关文章
- eclipse使用maven打包时去掉测试类
eclipse使用maven打包时去掉测试类 在pom.xml文件中增加如下配置: <plugin> <groupId>org.apache.maven.plugins< ...
- Javaspring+mybit+maven中实现Junit测试类
在一个Javaspring+mybit+maven框架中,增加Junit测试类. 在测试类中遇到的一些问题,利用spring 框架时,里面已经有保密security+JWT设定的场合,在你的secur ...
- Maven打包时过滤测试代码或指定特定的测试类(maven-surefire-plugin)
1.过滤整个测试代码,可以直接在命令行上指定 mvn clean install -Dmaven.test.skip=true 提示:以上为举例,具体的构建阶段可以自定义,其中maven.test.s ...
- Maven打包跳过测试
运行mvn install时跳过Test 方法一: <project> [...] <build> <plugins> <plugin> <gro ...
- Maven打包跳过测试,文档生成
运行mvn install时跳过Test 方法一: <project> [...] <build> <plugins> <plugin> <gro ...
- Maven打包命令
mvn clean 会把原来target目录给删掉重新生成.mvn install 安装当前工程的输出文件到本地仓库,然后打包mvn clean install 先删除target文件夹 ,然后打包到 ...
- 【maven】Maven打包后为何文件大小改变了
项目中使用了X.509证书,用Maven打包后,测试时报错: java.security.cert.CertificateException: Could not parse certificate: ...
- Maven学习笔记-02-Maven项目打包配置与测试
一 Maven项目打包配置 1 为整个项目统一指定字符集 <properties> <project.build.sourceEncoding>UTF-</project ...
- maven打包如何跳过测试
Maven打包如何跳过测试?正常来说,不应该这样做,因为测试可以避免很多麻烦排除一些不必要的错误,前提是测试足够规范,这里主要指junit测试,如果junit测试有问题的话,将会直接影响到mvn in ...
随机推荐
- You Don't Know JS: Async & Performance(第2章,Callbacks)
Chapter 2: Callbacks. Callbacks are by far the most common way that asynchrony in JS programs is exp ...
- BFS+二进制状态压缩 hdu-1429
好久没写搜索题了,就当练手吧. vis[][][1025]第三个维度用来维护不同key持有状态的访问情况. 对于只有钥匙没有对应门的位置,置为'.',避免不必要的状态分支. // // main.cp ...
- Confluence 6 权限概述
下面的权限可以指派给任何一个空间: 分类 权限 全部(All) 查看(View )给你能够查看空间内容的权限,包括有空间目录和其他的内容,例如主面板. 删除自己(Delete own) 给你权限删除你 ...
- ModelViewSet 视图集 实现接口
一.创建项目 1.创建 项目 : django-admin startprojet drf 2. 创建 两个app ------ app1 ,book python manage.py start ...
- javascript之动画特效
JavaScript的动画用的最多的3个api就是setInterval().setTimeout()和requestAnimationFrame()
- Oracle PL/SQL游标
游标的提出: SQL是面向集合的,其结果一般是集合量(多条记录),而PL/SQL的变量一本是标量,其一组变量异常一直只能存放一条记录.所以仅仅使用变量并不能完全满足SQL语句向应用程序输出数据的要求. ...
- leetcode-algorithms-14 Longest Common Prefix
leetcode-algorithms-14 Longest Common Prefix Write a function to find the longest common prefix stri ...
- PAT 1027 Colors in Mars
1027 Colors in Mars (20 分) People in Mars represent the colors in their computers in a similar way ...
- CSS text-decoration 属性
定义和用法 text-decoration 属性规定添加到文本的修饰. 注释:修饰的颜色由 "color" 属性设置. 说明 这个属性允许对文本设置某种效果,如加下划线.如果后代元 ...
- 78. Subsets C++回溯法
本题还是基本的回溯法.就是回溯函数的参数选择上要花点心思! class Solution { public: void backTrack(vector<int> ans, vector& ...