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.

JUnit でテスト用のデータを使用する(@Sqlアノテーション )

Posted at

概要

実行時点によって、データが変わってしまうので、
ユニットテストは、テスト用のデータで実行したいという場合、
@Sqlアノテーション を使用する。

1. テスト用のsqlを作成

src/main/resources 配下に、以下のようなsqlを作成する。

sample.sql
INSERT INTO sample (id, name)
VALUES(20, 'サンプル');

2.テストを作成

test.java
// @Sql()の中には`src/main/resources`以下のパスを書く
@Test
@Sql({"/newsRoutingTest.sql"})
public void sampleTest(){
  // テスト内容
}

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?