> For the complete documentation index, see [llms.txt](https://doczhcn.gitbook.io/junit5/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://doczhcn.gitbook.io/junit5/index/index-2/assumptions.md).

# 假设

JUnit Jupiter附带了JUnit4提供的一些assumption方法的子集，并增加了一些适合与Java 8 lambda一起使用的方法。所有的JUnit Jupiter assumption都是[`org.junit.jupiter.Asumptions`](http://junit.org/junit5/docs/current/api/org/junit/jupiter/api/Assumptions.html)类中的静态方法。

```java
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assumptions.assumeTrue;
import static org.junit.jupiter.api.Assumptions.assumingThat;

import org.junit.jupiter.api.Test;

class AssumptionsDemo {

    @Test
    void testOnlyOnCiServer() {
        assumeTrue("CI".equals(System.getenv("ENV")));
        // remainder of test
    }

    @Test
    void testOnlyOnDeveloperWorkstation() {
        assumeTrue("DEV".equals(System.getenv("ENV")),
            () -> "Aborting test: not on developer workstation");
        // remainder of test
    }

    @Test
    void testInAllEnvironments() {
        assumingThat("CI".equals(System.getenv("ENV")),
            () -> {
                // perform these assertions only on the CI server
                assertEquals(2, 2);
            });

        // perform these assertions in all environments
        assertEquals("a string", "a string");
    }

}
```
