1
0

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 3 years have passed since last update.

Gradleでテスト実行時の文字化け @Sql

Posted at

問題

  @Test
  @Sql({"/data.sql"})
  void 検索テスト() {
    TestData result = service.find();
    assertThat(result.getData()).isEqualTo("テスト");
  }

data.sqlで入れたデータを検索してassertするとき、
JUnitで実行の場合は成功するがGradleで実行した場合は文字化けが発生する。

状況

データベースに格納されたデータ自体が文字化けしている。

image.png

org.opentest4j.AssertionFailedError: 
expected: "テスト"
but was : "繝�繧ケ繝�"

原因

@Sql でデータ投入するとき文字化けしている。

結論

build.gradleにこの設定を追加する。
利用するファイルのエンコードをしてくれる模様。

build.gradle
tasks.withType(Test) {
    systemProperty "file.encoding", "UTF-8"
}

解決

image.png

1
0
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
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?