18
17

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

MavenでJUnit 4をテストするためのpom.xml

Posted at

JUnit 4のテストクラスは、mvn testしてもテストクラスがテストされない。どうやら、標準ではJUnit 3の方式で*Testクラスを探しに行ってる?っぽいので、pom.xmlで調整。

<build>
  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.16</version>
    <configuration>
      <argLine>-Dfile.encoding=UTF-8</argLine>
      <includes>
        <include>**/*.class</include>
      </includes>
      <excludes>
        <exclude>**/HogeTestRule.class</exclude>
      </excludes>
    </configuration>
  </plugin>
</build>

工夫した点は2つ。

  • configulationのargLineでfile.encodingをUTF-8に
    • 日本語メソッド名・クラス名・属性名を使っている所があるので、指定しないとエラーになる
  • ExternalResourceクラスを継承したテストルールクラスをテスト対象外へ
    • includesで全てのクラスを指定してるけど、テストルールはテストしないのでexclude化

これで、JUnit 4を使っていても、Mavenでビルド・テストできる。

18
17
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
18
17

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?