Test with Eclipse and Juint

Source: Internet
Author: User

After you open eclipse, click File in the upper-left corner, create a new project, name Testjunit, and then create a new two package in the SRC directory named Testscore and test (this is a folder with no files so it is white).

Create a new class in Testscore, named Score.java.

Package Testscore;
Import Java.util.Scanner;
public class Score {
private static String result;
private static String note;
public void Checkscore (int score) {
if (score<=100&&score>97) {result= "excellent"; note= "Pass";}
else if (score<=97&&score>94) {result= "score very high"; note= "Pass";}
else if (score<=94&&score>92) {result= "high score"; note= "Pass";}
else if (score<=92&&score>88) {result= "very good"; note= "Pass";}
else if (score<=88&&score>85) {result= "good"; note= "Pass";}
else if (score<=85&&score>82) {result= "very satisfied"; note= "Pass";}
else if (score<=82&&score>79) {result= "satisfied"; note= "Pass";}
else if (score<=79&&score>74) {result= "General"; note= "through";}
else if (score<=74&&score>50) {result= "can be increased"; note= "through";}
else if (score<=50&&score>0) {result= "difference"; note= "Pass";}
else {result= "indeterminate"; note= "indeterminate";}
}
Public String GetResult () {
return result;
}
public static void Main (string[] args) {
String input;
int score = 0;
System.out.println ("Please enter your score:");
Scanner reader = new Scanner (system.in);
input = Reader.nextline ();
try {
Score = Integer.parseint (input);
} catch (Exception e) {
SYSTEM.OUT.PRINTLN ("Hint: your input is wrong! Please check the input is correct!!! ");
}
Score Stu = new score ();
Stu. Checkscore (score);
System.out.println ("Your score evaluates to:" + result + ".) Note: "+ Note +". ");
}
}

then right click on Score.java, click on the JUnit test case in option new (if this option is not available, click Others, select JUnit test in JUnit), click Next, change the package to Test, Name change to Scoretest, click Next.

After entering test methods, check the Checkscore (int) and GetResult () two methods in score and click on Finsh.

after the new Scoretest.java, we need to import Testscore.score;

then declare an object score private static score score = new score ();

and "Fail" ("not yet implemented") in two methods; " by deleting,

Write the following code in Testcheckscore ():

Score. Checkscore (70);

Assertequals ("Can be Improved", Score.getresult ());

Write the following code in Testgetresult ():

Score. Checkscore (40);

Assertequals ("Poor", Score.getresult ());

After saving, right-click Scoretest.java, select Run as, and then select JUnit test to run JUnit to test if the data in Scoretest.java is correct. , the test results show the green bar, otherwise the red bar, you can follow the prompts to find the error.

Reference: http://jingyan.baidu.com/article/e4511cf35fd9fe2b845eafc7.html

Test with Eclipse and Juint

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.