zoukankan      html  css  js  c++  java
  • 单体测试—— Junit4.x

    l取代main方法快速测试程序
    l@Test: 测试方法(******)
    l@Ignore: 被忽略的测试方法
    l@Before: 在每个测试方法执行之前都要执行一次。
    l@After: 在每个测试方法执行之后要执行一次。
    l@BeforeClass: 所有测试开始之前运行 static
    l@AfterClass: 所有测试结束之后运行 static
    l使用断言判断测试结果
    •assertEquals(expected, actual)
    •assertNull(object)
    •assertNotNull(object)
    •assertTrue(condition)
    •assertFalse(condition)
    package cn.itcast.junit;
    
    import org.junit.After;
    import org.junit.AfterClass;
    import org.junit.Assert;
    import org.junit.Before;
    import org.junit.BeforeClass;
    import org.junit.Ignore;
    import org.junit.Test;
    
    public class Demo1 {
    
        public Demo1(String s) {
        }
    
        public Demo1(){}
        // 调用junit去测试demo1方法.
        @Test
        public void demo1() {
    
            System.out.println("hello demo1");
            // System.out.println(10/0);
        }
    
        @Test
        // @Ignore
        // 被忽略
        public void demo2() {
            System.out.println("hello demo2");
        }
    
        @Before
        // 在@Test这样的测试方法执行前要执行的方法
        public void demo3() {
            System.out.println("hello demo3");
        }
    
        @After
        // @Test方法在执行后要执行的方法.
        public void demo4() {
            System.out.println("hello demo4");
        }
    
        @AfterClass
        public static void demo5() {
            System.out.println("hello demo5");
        }
    
        @BeforeClass
        public static void demo6() {
            System.out.println("hello demo6");
        }
    
        // 断言
        @Test
        public void demo7() {
            // String s="abc";
            // Assert.assertNotNull(s);
    
            // String s=null;
    
            // Assert.assertNull(s);
    
        }
    
        // 通过主方法调用
        public static void main(String[] args) {
            // Demo1 d = new Demo1();
            // d.demo1();
        }
    }
  • 相关阅读:
    Maven 环境的配置
    zTree的简单例子
    plsql免安装客户端的配置
    HDU 1232 畅通工程
    HDU 5698 瞬间移动
    Codeforces 1015E1 Stars Drawing (Easy Edition)
    Codeforces 784B Santa Claus and Keyboard Check
    Codeforces 500C New Year Book Reading
    NSarray 赋值 拷贝 等问题记录
    UINavigationController 操作记录
  • 原文地址:https://www.cnblogs.com/spadd/p/4190822.html
Copyright © 2011-2022 走看看