package com.xxx.test.junit;
import lombok.extern.slf4j.Slf4j;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
@Slf4j
public class MyUtilsTest {
@Before
public void before() {
log.info("before##################创建对象");
log.info("每个方法都执行##################每个方法都执行");
}
@After
public void after() {
log.info("after###################销毁对象");
log.info("每个方法都执行##################每个方法都执行");
}
@BeforeClass
public static void beforeClass() {
log.warn("beforeClass##################创建对象");
log.warn("只执行一次##################只执行一次");
}
@AfterClass
public static void afterClass() {
log.warn("afterClass###################销毁对象");
log.warn("只执行一次##################只执行一次");
}
@Test
public void testIsEmpty() {
boolean result = MyUtils.isEmpty(null);
log.info("result: {}", result); // 结果:true
result = MyUtils.isEmpty("java某花宝典");
log.info("result: {}", result); // 结果:false
result = MyUtils.isEmpty("");
log.info("result: {}", result); // 结果:true
result = MyUtils.isEmpty(" ");
log.info("result: {}", result); // 结果:true
result = MyUtils.isEmpty(" ");
log.info("result: {}", result); // 结果:true
}
/** 时间测试 **/
@Test(timeout = 2000)
public void testPayTime() {
MyUtils.payTime(1000);
log.warn("payTime1:1000");
MyUtils.payTime(1000);
log.warn("payTime2:1000");
MyUtils.payTime(3000);
log.warn("payTime3:3000");
}
@Test(timeout = 2000)
public void testPayTime2() {
MyUtils.payTime(1900);
log.warn("payTime1:1900");
}
@Test
public void testThrowErr2() {
log.warn("测试不通过");
MyUtils.throwErr();
}
/** 异常测试 **/
@Test(expected = ArithmeticException.class)
public void testThrowErr() {
log.warn("测试通过");
log.warn("start~~~~~~~~~~~~~~~");
MyUtils.throwErr();
}
}
欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/) | Powered by Discuz! X3.2 |