Maven学习13之覆盖率测试

1.build的时候的goals为:

cobertura:cobertura

2.运行之后在site下面可以看到html文件

3.运行记录:

[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building MavenLearning 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] >>> cobertura-maven-plugin:2.7:cobertura (default-cli) > [cobertura]test @ MavenLearning >>>
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ MavenLearning ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory D:\all\eclipse432\MavenLearning\src\main\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ MavenLearning ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- cobertura-maven-plugin:2.7:instrument (default-cli) @ MavenLearning ---
[INFO] Cobertura 2.1.1 - GNU GPL License (NO WARRANTY) - See COPYRIGHT file
[INFO] Cobertura: Loaded information on 1 classes.
[INFO] Cobertura: Saved information on 1 classes.
[INFO] Cobertura: Saved information on 1 classes.

[INFO] Instrumentation was successful.
[INFO] NOT adding cobertura ser file to attached artifacts list.
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ MavenLearning ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory D:\all\eclipse432\MavenLearning\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ MavenLearning ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 4 source files to D:\all\eclipse432\MavenLearning\target\test-classes
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ MavenLearning ---
[INFO] Surefire report directory: D:\all\eclipse432\MavenLearning\target\surefire-reports

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running org.xubo.maven.MavenLearning.AppTest
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.042 sec
Running org.xubo.maven.MavenLearning.CopyOfHelloWorldTest
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.009 sec <<< FAILURE!
initializationError(org.xubo.maven.MavenLearning.CopyOfHelloWorldTest)  Time elapsed: 0.009 sec  <<< ERROR!
java.lang.Exception: Method testHello() should be public
	at org.junit.runners.model.FrameworkMethod.validatePublicVoid(FrameworkMethod.java:88)
	at org.junit.runners.model.FrameworkMethod.validatePublicVoidNoArg(FrameworkMethod.java:66)
	at org.junit.runners.ParentRunner.validatePublicVoidNoArgMethods(ParentRunner.java:122)
	at org.junit.runners.BlockJUnit4ClassRunner.validateTestMethods(BlockJUnit4ClassRunner.java:193)
	at org.junit.runners.BlockJUnit4ClassRunner.validateInstanceMethods(BlockJUnit4ClassRunner.java:168)
	at org.junit.runners.BlockJUnit4ClassRunner.collectInitializationErrors(BlockJUnit4ClassRunner.java:115)
	at org.junit.runners.ParentRunner.validate(ParentRunner.java:269)
	at org.junit.runners.ParentRunner.<init>(ParentRunner.java:66)
	at org.junit.runners.BlockJUnit4ClassRunner.<init>(BlockJUnit4ClassRunner.java:59)
	at org.junit.internal.builders.JUnit4Builder.runnerForClass(JUnit4Builder.java:13)
	at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:57)
	at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:29)
	at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:57)
	at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:24)
	at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:250)
	at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:141)
	at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:112)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:606)
	at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189)
	at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165)
	at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85)
	at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:115)
	at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:75)

Running org.xubo.maven.MavenLearning.TestHelloWorld
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.021 sec <<< FAILURE!
initializationError(org.xubo.maven.MavenLearning.TestHelloWorld)  Time elapsed: 0.021 sec  <<< ERROR!
java.lang.Exception: Method testHello() should be public
	at org.junit.runners.model.FrameworkMethod.validatePublicVoid(FrameworkMethod.java:88)
	at org.junit.runners.model.FrameworkMethod.validatePublicVoidNoArg(FrameworkMethod.java:66)
	at org.junit.runners.ParentRunner.validatePublicVoidNoArgMethods(ParentRunner.java:122)
	at org.junit.runners.BlockJUnit4ClassRunner.validateTestMethods(BlockJUnit4ClassRunner.java:193)
	at org.junit.runners.BlockJUnit4ClassRunner.validateInstanceMethods(BlockJUnit4ClassRunner.java:168)
	at org.junit.runners.BlockJUnit4ClassRunner.collectInitializationErrors(BlockJUnit4ClassRunner.java:115)
	at org.junit.runners.ParentRunner.validate(ParentRunner.java:269)
	at org.junit.runners.ParentRunner.<init>(ParentRunner.java:66)
	at org.junit.runners.BlockJUnit4ClassRunner.<init>(BlockJUnit4ClassRunner.java:59)
	at org.junit.internal.builders.JUnit4Builder.runnerForClass(JUnit4Builder.java:13)
	at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:57)
	at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:29)
	at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:57)
	at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:24)
	at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:250)
	at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:141)
	at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:112)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:606)
	at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189)
	at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165)
	at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85)
	at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:115)
	at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:75)

Results :

Tests in error:
  initializationError(org.xubo.maven.MavenLearning.CopyOfHelloWorldTest): Method testHello() should be public
  initializationError(org.xubo.maven.MavenLearning.TestHelloWorld): Method testHello() should be public

Tests run: 3, Failures: 0, Errors: 2, Skipped: 0

[ERROR] There are test failures.

Please refer to D:\all\eclipse432\MavenLearning\target\surefire-reports for the individual test results.
[INFO]
[INFO] <<< cobertura-maven-plugin:2.7:cobertura (default-cli) < [cobertura]test @ MavenLearning <<<
[INFO]
[INFO] --- cobertura-maven-plugin:2.7:cobertura (default-cli) @ MavenLearning ---
[INFO] Cobertura 2.1.1 - GNU GPL License (NO WARRANTY) - See COPYRIGHT file
[INFO] Cobertura: Loaded information on 1 classes.
Report time: 103ms

[INFO] Cobertura Report generation was successful.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 5.397 s
[INFO] Finished at: 2016-05-10T17:10:55+08:00
[INFO] Final Memory: 24M/166M
[INFO] ------------------------------------------------------------------------

4.pom:

<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>org.xubo.maven</groupId>
	<artifactId>MavenLearning</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<packaging>jar</packaging>

	<name>MavenLearning</name>
	<url>http://maven.apache.org</url>

	<properties>
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
		<junit.version>4.11</junit.version>
	</properties>

	<dependencies>
		<dependency>
			<groupId>junit</groupId>
			<artifactId>junit</artifactId>
			<version>4.8.1</version>
			<scope>test</scope>
		</dependency>

		<dependency>
			<groupId>log4j</groupId>
			<artifactId>log4j</artifactId>
			<version>1.2.17</version>
			<scope>compile</scope>
		</dependency>
	</dependencies>

	<!-- <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId>
		<artifactId>maven-surefire-plugin</artifactId> <version>2.18.1</version>
		</plugin> </plugins> </build> -->

</project>
时间: 2024-11-07 19:13:32

Maven学习13之覆盖率测试的相关文章

Maven学习三 使用junit测试maven project

每个开发人员都会对自己的代码进行自定义的测试,可以是把项目run起来,手动点点页面按钮,看看操作场景和步骤点是否符合业务需要,是否存在UE上的问题.也有自己写几个测试类,把service类的输入输出是否符合标准都测试一番,这两大类,其实就是包括了前后端的测试工作,分工各有不同.在maven中集成了junit测试包,应该说maven可以集成任何你想的到或者想不到工具插件. 在maven project-01项目中引入junit插件并不困难,只需要在pom.xml中配置好依赖包即可(IDE环境下,依

Maven学习总结

转载至:http://www.cnblogs.com/xdp-gacl/p/3498271.html 一 入门 一.Maven的基本概念 Maven(翻译为"专家","内行")是跨平台的项目管理工具.主要服务于基于Java平台的项目构建,依赖管理和项目信息管理. 1.1.项目构建 项目构建过程包括[清理项目]→[编译项目]→[测试项目]→[生成测试报告]→[打包项目]→[部署项目]这几个步骤,这六个步骤就是一个项目的完整构建过程. 理想的项目构建是高度自动化,跨平台

Maven学习总结(二)——Maven项目构建过程练习

Maven学习总结(二)——Maven项目构建过程练习 上一篇只是简单介绍了一下maven入门的一些相关知识,这一篇主要是体验一下Maven高度自动化构建项目的过程 一.创建Maven项目 1.1.建立Hello项目 1.首先建立Hello项目,同时建立Maven约定的目录结构和pom.xml文件 Hello | --src | -----main | ----------java | ----------resources | -----test | ---------java | -----

Maven学习笔记之——仓库(中)

Maven学习笔记之--仓库(中) 1.    远程仓库的配置 当出现默认的中央仓库无法满足我们的需求或者连接不上的时候.我们可以通过POM文件来指定远程仓库. <repositories> <repository> <id>jboss-maven2-release-repository</id> <name>JBoss Repository</name> <url>http://repository.jboss.org/

Maven学习总结(四)——Maven核心概念

一.Maven坐标 1.1.什么是坐标? 在平面几何中坐标(x,y)可以标识平面中唯一的一点. 1.2.Maven坐标主要组成 groupId:组织标识(包名) artifactId:项目名称 version:项目的当前版本 packaging:项目的打包方式,最为常见的jar和war两种 样例: 1.3.Maven为什么使用坐标? Maven世界拥有大量构建,我们需要找一个用来唯一标识一个构建的统一规范. 拥有了统一规范,就可以把查找工作交给机器. 二.依赖管理 2.1.依赖配置 依赖配置主要

Maven学习-目录结构

Maven学习-入门 1. 什么是Maven 2. 如何用Maven来构建项目 3. Maven项目的目录结构 Maven约定了一套规则来创建和构建项目.得益于Maven的一些约定,我们只要学习相对很少的命令就可以创建和管理我们的项目.在项目的目录结构上,Maven有一套约定的通用的目录结构. 使用一套通用的目录结构的好处是,可以减少开发人员熟悉不同Maven项目时的认知负担.在使用相同的目录结构的情况下,开发人员可以很快的熟悉一个项目. 1.Maven通用的目录结构介绍 通用目录结构 Mave

Maven学习笔记之——仓库(上)

Maven学习笔记之--仓库(上) 1.    何为maven仓库 Maven可以在某一指定位置统一存放所有maven项目共享的构件.此指定位置就是maven仓库.实际的项目将不再自己存放其所依赖的构件.他们只需要声明这些依赖的坐标.在需要的时候就会自动根据坐标找到仓库中的构件.并使用他们. 仓库的意义:减少磁盘占用空间.去除大量重复的构件.尤其是项目越来越多.越来越大的时候.更便于统一管理所有控件. 2.    仓库的布局 任何一个构件都有其唯一的坐标.根据这个坐标可以定义其在仓库中的唯一存储

Maven学习笔记之——坐标和依赖(上)

Maven学习笔记之--坐标和依赖(上) 1.    Maven坐标概念 Maven通过构件的坐标来在Maven仓库中定位到具体的构件.Maven的坐标元素包括groupId.artifactId.versiion.packaging.classifier.Maven内置了一个中央仓库地址.需要时Maven会根据坐标到其中下载.具体关于中央仓库的介绍在后面. 2.    Maven坐标详解 比如下面一组坐标: <groupId>org.andy.items</groupId> &l

Maven学习(一)—— 概述

为接手gxpt准备已经快一个月了从SSH2-->EJB-->环境搭建-->Maven的构建.下面就带领大家初始Maven 一.什么是Maven. Maven是一个垮平台的项目管理工具,主要服务于Java平台的项目构建.依赖管理和项目信息管理.Maven是一个能够帮我们自动化构建过程,充清理.编译.测试到生成报告,再到打包和部署.我们不需要一遍又一遍的输入命令,这些工作Maven都为我们做好了.Maven最大化地消除了构建的重复.在Maven以前,十个项目可能有十种构建方式:有了Maven