j util

来源:互联网 发布:json数组转换java对象 编辑:程序博客网 时间:2024/05/20 04:31

在程序中加载进入j util。。



package com.zzxtit.java18.imp;


import org.junit.After;
import org.junit.Before;
import org.junit.Test;

public class JUnitTest {

    @Before
    public void beforePrint(){
        System.out.println("我在test之前执行,一般用作初始化操作!!!");
    }
    
    @Test
    public void testPrint() throws Exception{
        String userName = "hello world";
        
        System.out.println("hello Junit!!");
        
        System.out.println("------------->" + userName);
        
        throw new Exception("我故意产生的异常!!!!");
    }
    
    @After
    public void afterPrint(){
        System.out.println("我在Test之后执行,一般用作资源的关闭操作!!!");
    }
    
}

在写代码时,可以单独运行一个方法,使用Test.

使用Before,在运行之前进行重置,

使用After,在运行后进行输出。

原创粉丝点击