3014218146_段义海_Lab1,第一次上机,学习使用JUnit,Hamcrest,Eclemma

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了3014218146_段义海_Lab1,第一次上机,学习使用JUnit,Hamcrest,Eclemma相关的知识,希望对你有一定的参考价值。

 

1. Build a project

技术分享

    Write the code

package lib1;



public class Triangle {
    public static String triganles (int a, int b, int c){
        if(a+b > c && a+c > b && b+c > a){
        if (a == b && b == c)
            return "this is a equilateral triganle!";
        else if (a == b || b == c || c == a)
            return "this is a isosceles triganle!";
        else
            return "this is a scalene triganle!";
            
        }
        else
        return "this is not triganle!";
    }
    
    
}

2.Install Junit(4.12), Hamcrest(1.3) with Eclipse

  A)   download Junit(4.12), Hamcrest(1.3)

  B)   Click the project with the right button, select properties ->Java Build Path ->Libraries->Add external JARs,

技术分享

Then select the junit-4.12.jar and Hamcrest-core-1.3

技术分享

3. Install Eclemma

  a)  Put the Eclemma.zip under the directory D:\\Program Files\\eclipse\\eclipse\\dropins ,decompress it.

  b)技术分享

  Click help->install new software->add

  技术分享

  Select the right path

  Ok! 

4.Add a source folder which will contain test package and the test class.

  技术分享

   it has the same package name as the package in src.

5. Write test code.

package lib1;

import static org.junit.Assert.*;

import org.junit.Test;

public class TestTriangle {

    @Test
    public void testTriangle() {
        assertEquals("this is not triganle!",new Triangle().triganles(1,2,3));
        assertEquals("this is a equilateral triganle!",new Triangle().triganles(1,1,1));
        assertEquals("this is a isosceles triganle!",new Triangle().triganles(2,2,3));
        assertEquals("this is a scalene triganle!",new Triangle().triganles(2,3,4));
    }

}

6. Run it as JUnit test and use eclemma.

技术分享

The coverage is 100%.

 

以上是关于3014218146_段义海_Lab1,第一次上机,学习使用JUnit,Hamcrest,Eclemma的主要内容,如果未能解决你的问题,请参考以下文章

Lab_1:练习2——使用qemu执行并调试lab1中的软件

TJU_SCS_软件测试_Lab1

[软件测试_LAB1]安装junit和hamcrest及其使用

6.s081 lab1

PL/SQL 上机练习

SDN第三次上机作业