質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
JUnit

JUnitは、Javaで開発されたプログラムのユニットテストを行うためのアプリケーションフレームワークです。簡単にプログラムのユニットテストを自動化することができ、結果もわかりやすく表示されるため効率的に開発時間を短縮できます。

Java

Javaは、1995年にサン・マイクロシステムズが開発したプログラミング言語です。表記法はC言語に似ていますが、既存のプログラミング言語の短所を踏まえていちから設計されており、最初からオブジェクト指向性を備えてデザインされています。セキュリティ面が強力であることや、ネットワーク環境での利用に向いていることが特徴です。Javaで作られたソフトウェアは基本的にいかなるプラットフォームでも作動します。

Eclipse

Eclipseは、IBM社で開発された統合開発環境のひとつです。2001年11月にオープンソース化されました。 たくさんのプラグインがあり自由に機能を追加をすることができるため、開発ツールにおける共通プラットフォームとして位置づけられています。 Eclipse自体は、Javaで実装されています。

Q&A

解決済

1回答

298閲覧

eclipseでJunit5を使用しJacocoレポートを生成したい

Mitsuki

総合スコア4

JUnit

JUnitは、Javaで開発されたプログラムのユニットテストを行うためのアプリケーションフレームワークです。簡単にプログラムのユニットテストを自動化することができ、結果もわかりやすく表示されるため効率的に開発時間を短縮できます。

Java

Javaは、1995年にサン・マイクロシステムズが開発したプログラミング言語です。表記法はC言語に似ていますが、既存のプログラミング言語の短所を踏まえていちから設計されており、最初からオブジェクト指向性を備えてデザインされています。セキュリティ面が強力であることや、ネットワーク環境での利用に向いていることが特徴です。Javaで作られたソフトウェアは基本的にいかなるプラットフォームでも作動します。

Eclipse

Eclipseは、IBM社で開発された統合開発環境のひとつです。2001年11月にオープンソース化されました。 たくさんのプラグインがあり自由に機能を追加をすることができるため、開発ツールにおける共通プラットフォームとして位置づけられています。 Eclipse自体は、Javaで実装されています。

0グッド

0クリップ

投稿2024/02/26 09:36

実現したいこと

eclipse上でmavenプロジェクトを作成し、Junit5を用いて単体テストとjacocoレポートを生成できるようにしたい。

発生している問題・分からないこと

Junt5をビルドパスに追加し、EclipseマーケットプレイスでJacocoプラグインをインストールしようとしたのですが接続できなかったため、pom.xmlに依存情報などを記述しました。その後テストクラスをJunit5で実行するところまではできたのですが、tagretフォルダにsiteフォルダやJacocoレポートが生成されません。
また、エラーはなく、eclipseの起動時に、
eclipse.buildId=4.30.0.20231201-1200
java.version=17.0.10
java.vendor=Eclipse Adoptium
BootLoader constants: OS=win32, ARCH=x86_64, WS=win32, NL=ja_JP
Framework arguments: -product org.eclipse.epp.package.java.product
Command-line arguments: -os win32 -ws win32 -arch x86_64 -product org.eclipse.epp.package.java.product
といった内容の警告がありました。

該当のソースコード

pom.xml

1<?xml version="1.0" encoding="UTF-8"?> 2 3<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 4 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 5 <modelVersion>4.0.0</modelVersion> 6 7 <groupId>JavaPractice</groupId> 8 <artifactId>JacocoSample</artifactId> 9 <version>0.0.1-SNAPSHOT</version> 10 11 <name>JacocoSample</name> 12 <!-- FIXME change it to the project's website --> 13 <url>http://www.example.com</url> 14 15 <properties> 16 <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 17 <maven.compiler.source>1.7</maven.compiler.source> 18 <maven.compiler.target>1.7</maven.compiler.target> 19 </properties> 20 21 <dependencies> 22 <dependency> 23 <groupId>junit</groupId> 24 <artifactId>junit</artifactId> 25 <version>4.11</version> 26 <scope>test</scope> 27 </dependency> 28 29 </dependencies> 30 31 <build> 32 <pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) --> 33 <plugins> 34 <!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle --> 35 <plugin> 36 <artifactId>maven-clean-plugin</artifactId> 37 <version>3.1.0</version> 38 </plugin> 39 <!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging --> 40 <plugin> 41 <artifactId>maven-resources-plugin</artifactId> 42 <version>3.0.2</version> 43 </plugin> 44 <plugin> 45 <artifactId>maven-compiler-plugin</artifactId> 46 <version>3.8.0</version> 47 </plugin> 48 <plugin> 49 <artifactId>maven-surefire-plugin</artifactId> 50 <version>2.22.1</version> 51 </plugin> 52 <plugin> 53 <artifactId>maven-jar-plugin</artifactId> 54 <version>3.0.2</version> 55 </plugin> 56 <plugin> 57 <artifactId>maven-install-plugin</artifactId> 58 <version>2.5.2</version> 59 </plugin> 60 <plugin> 61 <artifactId>maven-deploy-plugin</artifactId> 62 <version>2.8.2</version> 63 </plugin> 64 <!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle --> 65 <plugin> 66 <artifactId>maven-site-plugin</artifactId> 67 <version>3.7.1</version> 68 </plugin> 69 <plugin> 70 <artifactId>maven-project-info-reports-plugin</artifactId> 71 <version>3.0.0</version> 72 </plugin> 73 74 <plugin> 75 <groupId>org.jacoco</groupId> 76 <artifactId>jacoco-maven-plugin</artifactId> 77 <version>0.8.11</version> 78 </plugin> 79 80 </plugins> 81 </pluginManagement> 82 83 <plugins> 84 <plugin> 85 <groupId>org.jacoco</groupId> 86 <artifactId>jacoco-maven-plugin</artifactId> 87 <executions> 88 <execution> 89 <id>prepare-agent</id> 90 <goals> 91 <goal>prepare-agent</goal> 92 </goals> 93 </execution> 94 <execution> 95 <id>report</id> 96 <goals> 97 <goal>report</goal> 98 </goals> 99 </execution> 100 </executions> 101 </plugin> 102 </plugins> 103 104 </build> 105</project>

Account.java

AccountTest.java

1package JavaPractice.JacocoSample; 2 3import static org.junit.jupiter.api.Assertions.*; 4 5import org.junit.jupiter.api.Test; 6 7class AccountTest { 8 9 @Test 10 public void instantiate() { 11 Account a = new Account("ミナト", 30000); 12 assertEquals("ミナト", a.owner); 13 assertEquals(30000, a.zandaka); 14 } 15} 16

試したこと・調べたこと

  • teratailやGoogle等で検索した
  • ソースコードを自分なりに変更した
  • 知人に聞いた
  • その他
上記の詳細・結果

学習目的でIDEやフレームワークを始めた初心者です。ネットやAIで、プロジェクトの作成方法やビルドファイルの記述方法、mavenについて調べました。特にpom.xmlはeclipseで自動で記述されたものに、AIが生成したJacocoの依存情報(<dependency><plugin>)などをコピペしました。

補足

eclipse Version: 2023-12 (4.30.0)
Java 21
メニューバーのウィンドウの設定でJava下のインストール済みのJREで確認しました。初心者なのでこれが正しいかどうかはわかりません。すみません。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

自己解決

※以下の方法でJacocoカバレッジは出力できたのですが、不具合が見つかったため再度質問を投稿しました。

jacocoのガバレッジが出力できたので、解決方法を記載しておきます。

以前までは、Eclipseマーケットプレイスに上手く接続できなかったのですが、今回は問題なく接続できました。ここで「EclEmma Java コード・ガバレッジ 3.1.8」をインストールをしようとしたのですが、自分の環境では既にインストールされていました。

以下の記事を参考にビルドファイルを作成しました。尚、Junit5はJunit Jupiterと依存関係があることから、Junit Jupiterのdepedencyタグを追記しました。(24~35行目)

参考
https://yamap-55.hatenadiary.org/entry/20140727/1406438741

pom.xml

1<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 2 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 3 <modelVersion>4.0.0</modelVersion> 4 5 <groupId>JavaPractice</groupId> 6 <artifactId>JacocoSample</artifactId> 7 <version>0.0.1-SNAPSHOT</version> 8 <packaging>jar</packaging> 9 10 <name>JacocoSample</name> 11 <url>http://maven.apache.org</url> 12 13 <properties> 14 <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 15 </properties> 16 17 <dependencies> 18 <dependency> 19 <groupId>junit</groupId> 20 <artifactId>junit</artifactId> 21 <version>3.8.1</version> 22 <scope>test</scope> 23 </dependency> 24 <dependency> 25 <groupId>org.junit.jupiter</groupId> 26 <artifactId>junit-jupiter-api</artifactId> 27 <version>5.10.2</version> 28 <scope>test</scope> 29 </dependency> 30 <dependency> 31 <groupId>org.junit.jupiter</groupId> 32 <artifactId>junit-jupiter-engine</artifactId> 33 <version>5.10.2</version> 34 <scope>test</scope> 35 </dependency> 36 </dependencies> 37 38 <build> 39 <pluginManagement> 40 <plugins> 41 <plugin> 42 <groupId>org.apache.maven.plugins</groupId> 43 <artifactId>maven-surefire-plugin</artifactId> 44 <configuration> 45 <argLine>${jacocoArgs}-Xmx256m -XX:MaxPermSize=256</argLine> 46 </configuration> 47 </plugin> 48 </plugins> 49 </pluginManagement> 50 <plugins> 51 <plugin> 52 <groupId>org.jacoco</groupId> 53 <artifactId>jacoco-maven-plugin</artifactId> 54 <version>0.8.11</version> 55 <executions> 56 <execution> 57 <id>prepare-agent</id> 58 <phase>test-compile</phase> 59 <goals> 60 <goal>prepare-agent</goal> 61 </goals> 62 <configuration> 63 <propertyName>jacocoArgs</propertyName> 64 <includes> 65 <include>*</include> 66 </includes> 67 </configuration> 68 </execution> 69 <execution> 70 <id>report</id> 71 <phase>prepare-package</phase> 72 <goals> 73 <goal>report</goal> 74 </goals> 75 </execution> 76 </executions> 77 </plugin> 78 </plugins> 79 </build> 80 <reporting> 81 <plugins> 82 <plugin> 83 <groupId>org.jacoco</groupId> 84 <artifactId>jacoco-maven-plugin</artifactId> 85 </plugin> 86 </plugins> 87 </reporting> 88</project>

実行する際にコマンドを入力する必要があったため、以下の記事を参考に外部ツールの構成で、シェルを起動できるよう設定しました。

参考
https://www.gwtcenter.com/invoke-cmd-on-eclipse-project

次のコマンドで実行しました。

mvn clean jacoco:prepare-agent test jacoco:report

また、jacocoレポートは、target/site/jacocoフォルダにあるindex.htmlをブラウザで開くことで確認できました。

投稿2024/02/28 15:41

編集2024/02/29 13:36
Mitsuki

総合スコア4

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問