Java 断言 assert 用法

import org.junit.Test;

public class AssertUtil {

 @Test
 public void assertDemo1(){
  
  boolean isTrue = 1>2;//false
  assert isTrue;//java.lang.AssertionError
  System.out.println("程序正常");  
 }
 
 @Test
 public void assertDemo2(){
  
  boolean isTrue = 1>2;
  assert isTrue : "我断言程序错误 !";
  System.out.println("程序正常");  
 }
}

猜你喜欢

转载自xiongjiajia.iteye.com/blog/2327102