Environment Variables

EnvironmentVariables可以在测试之前设置环境变量,并在测试之后恢复

    package com.junit.learning.systemtest;

    import org.junit.Rule;
    import org.junit.Test;
    import org.junit.contrib.java.lang.system.EnvironmentVariables;

    import static org.assertj.core.api.Assertions.assertThat;

    public class EnvironmentVariablesTest {
        @Rule
        public final EnvironmentVariables environmentVariables
                = new EnvironmentVariables();

        @Test
        public void setEnvironmentVariable() {
            environmentVariables.set("name", "value");
            assertThat(System.getenv("name")).isEqualTo("value");
        }
    }
Copyright © www.gitbook.com/@herryZ 2016 all right reserved,powered by Gitbook该文件修订时间: 2017-03-13 05:37:11

results matching ""

    No results matching ""