1 断言

image.png

  1. class Assertion {
  2. public static void main(String[] args) {
  3. assert hypotenuse(3, 4) == 5 : "算法不正确";
  4. }
  5. static double hypotenuse(double x, double y) {
  6. return Math.sqrt(x*x + y*y + 1);
  7. }
  8. }
  9. // 上面的程序会导致产生异常

image.png

2 JUnit

image.png
image.png
image.png