– Start
如果你的测试用例需要在某些特定条件下运行,JUnit 提供了以下方法。
package demo10;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.DisabledIfEnvironmentVariable;
import org.junit.jupiter.api.condition.DisabledIfSystemProperty;
import org.junit.jupiter.api.condition.DisabledOnJre;
import org.junit.jupiter.api.condition.DisabledOnOs;
import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;
import org.junit.jupiter.api.condition.EnabledIfSystemProperty;
import org.junit.jupiter.api.condition.EnabledOnJre;
import org.junit.jupiter.api.condition.EnabledOnOs;
import org.junit.jupiter.api.condition.JRE;
import org.junit.jupiter.api.condition.OS;
class ConditionTest {
@BeforeAll
static void setUpBeforeClass() throws Exception {
System.setProperty("env", "dev");
}
//
// Operating System Conditions
// 操作系统
//
@Test
@EnabledOnOs(OS.WINDOWS)
void onlyOnWindows() {
Sys