0
0

More than 1 year has passed since last update.

JUnit5で環境変数が指定されていない場合にテストを実行しないようにする

Last updated at Posted at 2021-10-23

EnabledIfEnvironmentVariableアノテーションをクラスまたはメソッドに付与する。複数の環境変数が必要な場合はEnabledIfEnvironmentVariablesを使用する。

import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;
import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariables;

@EnabledIfEnvironmentVariables({
    @EnabledIfEnvironmentVariable(named = "HOGE", matches = ".*"),
    @EnabledIfEnvironmentVariable(named = "FUGA", matches = ".*")
})
public class SampleTests {

Visual Studio Codeの場合はsettings.jsonに環境変数を指定しておくとGUIでもテストが実行できる。

settings.json
    "java.test.config": {
        "env": {
            "HOGE": "foo",
            "FUGA": "bar"
        }
    }
0
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
0
0