Software Test Job (ii)

Source: Internet
Author: User

1. install JUnit and hamcrest under Eclipse .

  Pre-preparation: download JUnit and hamcrest jar packages to provide github download URLs

Https://github.com/junit-team/junit/wiki/Download-and-Install

After downloading the two jar packages, open Eclipse, create a new Java project, right-click on the Completed project folder and select the BuildPath option. Then, in the popup window, do the following: select "Libraries", click "Add External JARS", select the download path of the two jar packages above, select the jar package.

2. install eclemma under Eclipse

There are many ways to install Eclemma, and here is an online one-click installation method:

Open Eclipse, select Help->eclipsemarketplace

In the window that appears, select Search, fill in the "Eclemma" in the input box, click the Search button to display the search results, click Install directly at the search results.

After installation, restart Eclipse, when this button appears on the toolbar, the Eclemma installation is successful.

3. Write code to complete the detection of the triangle shape

According to the experimental requirements, this experiment requires testing code for a section of the code to detect a triangle shape: Given the length of the triangle three sides, to determine whether the triangle is equilateral triangle or isosceles triangle or ordinary triangles.

public class Tri {

Public String judgement (int a, int b, int c) {

if (a+b<=c | | a+c<=b | | b+c <=a) {

Return "not a triangle";

}else{

if (a==b&&a==c) {

return "equilateral";

}else if (a = = c && b! = c) {

return "Isosceles";

}else{

return "Scalene";

}

}

}

}

After the Triangle class is written, test functions are written, given the input and expected output, and tested by JUnit.

Import Org.junit.Test;

Import static org.junit.assert.*;

Import Org.junit.Before;

public class Main {

Public Tri t;

@Before

public void Create () {

t = new Tri ();

}

@Test

public void Test () {

Assertequals ("equilateral", T.judgement (1,1,1));

Assertequals ("Isosceles", T.judgement (1,2,2));

Assertequals ("Isosceles", T.judgement (2,1,2));

Assertequals ("Not a triangle", t.judgement ();

Assertequals ("Scalene", T.judgement (3,4,5));

}

}

 4. Test Results

JUnit Test

Coverage test under Eclemma (code snippet)

  

Software Test Job (b)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.