詳細
Gradleプロジェクトを作成します。
build.gradleに下記の設定を追加することでカバレッジを計測します。
build.gradle
buildscript { repositories { mavenCentral() } dependencies { classpath "net.saliman:gradle-cobertura-plugin:1.1.2" } } apply plugin: 'cobertura' dependencies { // 他の依存の設定 testCompile 'net.saliman:gradle-cobertura-plugin:1.1.2' } test { // VM引数に下記の設定をしないとcoberturaの実行が失敗する test.jvmArgs '-XX:-UseSplitVerifier' }
分岐の片側だけ通すテストを記載時
プロダクトコード
package org.gradle; public class Hoge { public String hoge(boolean hage) { if (hage) { return "hage"; } else { return "hige"; } } }
テストコード
package org.gradle; import static org.hamcrest.CoreMatchers.*; import static org.junit.Assert.*; import org.junit.Test; public class HogeTest { @Test public void test() { Hoge hoge = new Hoge(); assertThat(hoge.hoge(true), is("hage")); } }
分岐の両方だけ通すテストを追記
package org.gradle; import static org.hamcrest.CoreMatchers.*; import static org.junit.Assert.*; import org.junit.Test; public class HogeTest { @Test public void test() { Hoge hoge = new Hoge(); assertThat(hoge.hoge(true), is("hage")); assertThat(hoge.hoge(false), is("hige")); // <= ケース追加 } }