???????? ??????

????JAVA?е??????????????????????????д?Щ???????????????????????????????????????????????????????????????Bug????????Bug???? JUnit??????????????????????????????Bug?????磬????д??????????г????????????????????0????????????“??0??”????????????б??????Щ???в???????????£?

????@Test(expected = ArithmeticException.class)

????public void divideByZero() ...{

????calculator.divide(0);

????}

?????????????????????????????@Test?????expected????????????????????????????????JUnit?????????????????????????????????????

??????? Runner (??????)

?????????????????????????????????????JUnit?????????????????????????????——Runner????JUnit???к??? Runner?????????????????????????Runner???и???????????????????????????Runner????????????????????????????????????д?????????????????????????Runner??????????JUnit??????????Runner?????????????????????????????Runner???????????????仰??????????δ????????????????

????import org.junit.internal.runners.TestClassRunner;

????import org.junit.runner.RunWith;

????//???????????TestClassRunner?????????????????

????public class CalculatorTest ...{

????...

????}

????@RunWith(TestClassRunner.class)

????public class CalculatorTest ...{

????...

????}

???????????????????????????????Runner????????@RunWith???????????????????Runner???????????????????????????????@RunWith???????????????????????????κ????????????????????Runner???????????е????к??????????Runner?????á??????????????????Package??????????????????д????????????????????????????????Runner?????й????

?????塢 ??????????

???????????????????????????????????????????????????????????????????????磬??????????????????????????????????“????????????????????”??????????д?????????????д5???????????5??????????????????????????鷳?????顣?????????????????????????????“??????????????”????????????????????????0??????????????????£?

????import org.junit.AfterClass;

????import org.junit.Before;

????import org.junit.BeforeClass;

????import org.junit.Test;

????import static org.junit.Assert.*;

????public class AdvancedTest ...{

????private static Calculator calculator = new Calculator();

????@Before

????public void clearCalculator() ...{

????calculator.clear();

????}

????@Test

????public void square1() ...{

????calculator.square(2);

????assertEquals(4?? calculator.getResult());

????}

????@Test

????public void square2() ...{

????calculator.square(0);

????assertEquals(0?? calculator.getResult());

????}

????@Test

????public void square3() ...{

????calculator.square(-3);

????assertEquals(9?? calculator.getResult());

????}

????}