首页 > 编程语言 >java测试框架junit5

java测试框架junit5

时间:2023-02-11 12:55:37浏览次数:52  
标签:java 框架 assertEquals void System Test println junit5 out

1.常用注解

img

执行顺序:
BeforeAll  BeforEach > 测试用例 > AfterEach   BeforEach > 测试用例 > AfterEach  BeAfterAll

代码演示

public class DemoTest {
    @BeforeAll
    static void beforeAll(){
        System.out.println("开始测试。。。");
    }
    @AfterAll
    static void afterAll(){
        System.out.println("测试结束。。。");
    }
    @BeforeEach
    void setup(){
        System.out.println("打开浏览器");
    }
    @AfterEach
    void teardown(){
        System.out.println("关闭浏览器");
    }
    @Test
    void queryCaseTest(){
        System.out.println("query dates to ...");
        assertEquals(2,1+1);
    }
    @Test
    @DisplayName("登录测试")
    void loginCaseTest(){
        System.out.println("login to website");
        assertEquals(1,1);
    }
}

2.断言

img

代码演示:

public class JunitLearnTest {
    @Test
    void assertEqualsDemo1(){
        assertEquals("hello","hello");
    }
    @Test
    void assertAllDemo1(){
        assertAll("响应断言",
                ()->assertEquals(2,1),
                ()->assertEquals(2,2),
                ()->assertEquals(3,3)
        );

    }
    @Test
    void assertAllDemo2() throws InterruptedException{
        ArrayList<Executable> executables = new ArrayList<>();

        executables.add(()->assertEquals(2,2));
        executables.add(()->assertEquals(2,2));

        assertAll("执行流错误信息",executables.stream());
    }

3.参数化

public class JunitLearnTest {

    @ParameterizedTest
//    数据参数化
//    @CsvSource({"张三,14","李四,23","王五,34"})
    // 文件参数化
    @CsvFileSource(resources="/testData.csv",delimiterString = ",")
    void paramDemo(String name , Integer age){
        System.out.println(name+"的年龄是"+age+"岁");
    }

4.嵌套

5.测试套件

6.高级断言hamcrest

7.接入allure报告

标签:java,框架,assertEquals,void,System,Test,println,junit5,out
From: https://www.cnblogs.com/wn-graden/p/17111239.html

相关文章