[JAVA] How to batch run JUnit and get coverage as well

Introduction

I also write it as a memorandum for myself. I'm still new to SE and inexperienced in technology and knowledge, so there may be some mistakes. If there is something wrong, I would appreciate it if you could point it out. And if possible, be gentle. ..


Prerequisites

・ Windows10 64bit ・ Java7 -Eclipse Version: Luna Service Release 2 (4.4.2) The following plugins are installed ・ Junit ver 4.12 ・ Maven 4.0.0 ・ EclEmma 2.3.3 ・ Hudson / Jenkins 1.4.0

1. 1. Add jacoco to Maven dependency.

-Add the following statement to the pom.xml file

<!-- jacoco -->
<dependency>
  <groupId>org.jacoco</groupId>
  <artifactId>jacoco-maven-plugin</artifactId>
  <version>0.7.9</version>
  <scope>test</scope>
</dependency>

2. Make mvn command available

-First, add the maven installation path to the system environment variables

Example) Variable name: M2_HOME Path: D: \ apache-maven-3.3.9

-Add the following to the Path of the system environment %M2_HOME%\bin;

3. 3. Execute the following command in the project directory you want to execute

mvn clean org.jacoco:jacoco-maven-plugin:prepare-agent test -Dtest=Test.java
mvn org.jacoco:jacoco-maven-plugin:report


Supplement

↑ If you get this error, please change it.

◎ Reference site

http://qiita.com/umezo@github/items/e750d8e94663f36d9500 https://ishiis.net/2016/10/13/jacoco-coverage/ http://d.hatena.ne.jp/yamap_55/20140727/1406438741 http://wiki.tk2kpdn.com/use-maven-command/ http://d.hatena.ne.jp/joe-hs/20120414/1334388111 http://www.techscore.com/tech/Java/ApacheJakarta/Maven/3/

Recommended Posts

How to batch run JUnit and get coverage as well
How to execute and mock methods using JUnit
[Java] How to get and output standard input
How to get and study java SE8 Gold
How to use JUnit 5
How to run the SpringBoot app as a service
As of April 2018 How to get Java 8 on Mac
[Ruby] How to get the tens place and the ones place
[Kotlin] How to get IP address and user agent
How to use JUnit (beginner)
How to write Junit 5 organized
How to migrate from JUnit4 to JUnit5
[Creating] How to use JUnit
[Rails] How to get the URL of the transition source and redirect
[Swift5] How to get an array and the complement of arrays
How to read a file and treat it as standard input
How to run a job with docker login in AWS batch
How to get and add data from Firebase Firestore in Ruby
[Java] How to convert from String to Path type and get the path
How to get coverage of Android Instrumented Tests [Do your best]
How to use StringBurrer and Arrays.toString.
How to use Java HttpClient (Get)
How to get started with slim
How to use EventBus3 and ThreadMode
How to run Ant in Gradle
Get JUnit code coverage on Android.
How to run JavaFX on Docker
How to call classes and methods
How to use equality and equality (how to use equals)
How to connect Heroku and Sequel
How to get along with Rails
How to call libraries such as JQuery and JQuery UI in Liferay 7 / DXP
[Java] How to get the current date and time and specify the display format
How to display error messages and success messages when registering as a user
How to get the current date as a string in yyyyMMdd format
Use MyBatis to get Map with key as identifier and value as Entity
How to create your own annotation in Java and get the value
Install Webpacker and Yarn to run Rails
How to filter JUnit Test in Gradle
[Note] How to get started with Rspec
[Java] How to output and write files!
How to set up and use kapt
How to fix system date in JUnit
[Java] How to get the current directory
How to build SquashTM and how to support Japanese
How to find the tens and ones
How to get the date in java
How to use substring and substr methods
Note: [Docker] How to start and stop
How to write and explain Dockerfile, docker-compose
How to use @Builder and @NoArgsConstructor together
How to run Blazor (C #) with Docker
How to mount the batch file location via WSL2 and start the Docker container
How to perform UT with Excel as test data with Spring Boot + JUnit5 + DBUnit
[Spring sample code included] How to create a form and how to get multiple records
When defining a class, write formatTo as well as toString (how to use Formattable)