【软件测试】1st Experiment: Junit, Hamcrest and Eclemma

1. Experiment Purposes

  1. Install Junit(4.12), Hamcrest(1.3) with Eclipse
  2. Install Eclemma with Eclipse
  3. Write a java program for the triangle problem and test the program with Junit. 

2. Experiment Procedure

  1. Install the junit and hamcrest: Upload the 'junit-4.12.jar' and the 'hamcrest-all-1.3.jar' and add them to the new project 'TriangleTest';
  2. Install the EclemmaIn Eclipse: Help -> Install New Software -> add thr url and the name -> finished;
  3. Create the main class to judge wheater it can be a triangle(equilateral,isosceles,scalene) composed by given 3 number(a,b,c);
  4. Create a test class to do the testing, try the '@test, @BeforeClass, @AfterClass, @Before and @After';
  5. Try the coverage.

3. Experiment Results

  1. Test some annotations

    the source code:

    

    the console output:

    

  2. 4 test cases were used in the test class:(2,2,2), (2,2,1), (4,3,2), (0,3,2), and the result is :

    

  3. Coverage

    in the Triangle.java:

    

    in the TestTriangle.java:

    

    

原文地址:https://www.cnblogs.com/3013218071zjr/p/5292627.html