How to unit test with eclipse

Source: Internet
Author: User

1. Install an integrated development environment (available in Microsoft Visual Studio, Eclipse, or other tools) on your PC, requiring the environment to provide unit automated testing capabilities;

2, record the installation process, and publish all the content in the blog;

3. Implement maximal subarray and algorithm, and upload the code to the Coding.net system;

4, choose the appropriate coverage criteria and design test cases to test the code, and publish the test results in the blog, the results are completed in the form of the following table.

Use Case number

Use case description

Input data

Expected output data

Actual output data

Pass/No Pass

Evaluation

Eclipse was originally developed by IBM as an alternative business software for the next Generation IDE development environment of Visual age for Java, which was contributed to the open source community in November 2001 and is now made up of the non-profit software vendor Alliance Eclipse Foundation (eclipse Foundation) management. Therefore, it is a non-profit, focused on the development of highly integrated tools to provide a full-featured, commercial-quality industrial platform. Some of its understanding can be referenced in my last Post, "Analysis of different types of software," which describes my experience of using eclipse. Today's mission is mainly to explain the installation of Eclipse and to unit test the maximum subarray and algorithm using the JUnit tools that eclipse comes with.

  

First, installation of Eclipse

1.1. Download and install the JDK

Before installing eclipse, we need to build the Java development environment on the computer, that is, we need to install the JDK (the JDK with the JRE), the current version is the highest JDK8.0, you can go to the official website to search for downloads. Download to an EXE file as shown, then double-click Install, two, then follow the instructions. Note the installation path, and the next step is to configure the environment variables.

Figure A JDK installation file diagram

Figure II JDK Installation interface diagram

1.2. Configure Environment variables

After installing the JDK, we need to configure the environment variables of the computer. First Find My Computer (my system is win8.1), right-click Select Properties, select Advanced System settings, then select environment variables, operation process Three, and then create a new three environment variables are: variable name: path, variable value: The path of the Bin folder in the JDK; variable name: Classpath, Variable value: The path to the Lib folder in the JDK; variable name: java_home, Variable Value: The path to the JDK (if the variable name already exists, add the path you want to write in the value of the variable, separated by semicolons), four.

Figure III Environment Interface configuration diagram

Figure four environment variable configuration diagram

After configuring the environment variables, we use the DOS command prompt to test, enter java-version in the interface, if there is a five hint to prove the environment is successful, then we can install eclipse.

Figure five Environment Construction test diagram

1.3. Install Eclipse

Eclipse installation package We can download from the official website (www.eclipse.org), you can also find people around the copy-free compression package, decompression directly use. The specific installation process is not difficult, follow the instructions to step in one step down. In the following interface six.

Figure six Eclipse interface diagram

Implementation and testing of the maximal subarray and algorithm

2.1, maximum subarray and algorithm

I implemented the algorithm using the brute force enumeration method, seven, wrote a class, a method in the class to solve the maximum number of sub-arrays and programs. The specific code has been uploaded to coding (Https://coding.net/u/yuanjin/p/MaxArraySum/git/blob/master/sumMaxArray.java).

Figure Seven Code interface diagram

2.2, unit test of code

Next to the largest subarray written and tested, I used the Eclipse's own unit test tool JUnit, first click on file, New, select JUnit Text case, then select the class and method to test, eight, create success nine.

Figure Eight operation process diagram

Figure nine creating a successful interface diagram

Then write the test code, the specific code has been uploaded into coding (Https://coding.net/u/yuanjin/p/MaxArraySum/git/blob/master/sumMaxArrayTest.java). I have selected 7 sets of data to be tested including full positive, full negative, full 0, positive and 0, negative and 0, positive and negative, positive negative and 0, a total of seven cases, the first test results 10 shows that there are two sets of data test error.

Figure 10 First Test diagram

After careful study, I found the problem in the algorithm, start to assign the maximum value to zero, resulting in a negative error, so I set the initial value of the largest signed integer 0x7fffffff solved the problem, again test all pass, 11.

Figure 11 Test Success Diagram

2.3, the completion of the form

  

Use Case number

Use case description

Input data

Expected output data

Actual output data

Pass/No Pass

Evaluation

1

Full positive

{1,2,3,4}

10

10

Pass

Once passed, proving that the full positive algorithm is normal

2 Full negative { -1,-2,-3,-8,-4,-6,-9} -1 -1 Pass The first error, the maximum initial value problem, has been resolved
3 All zeros {0,0,0,0,0} 0 0 Pass One-time pass proves that all 0 algorithms are normal
4 Positive and 0 {2,22,0,10,17} 51 51 Pass Pass at once, prove positive and 0 algorithm normal
5 Negative numbers and 0 { -4,-2,0,-12,-1} 0 0 Pass Pass at once, prove negative and 0 algorithm normal
6 Positive and negative numbers {2,22,-10,17} 31 31 Pass The first error, the maximum initial value problem, has been resolved
7 Positive negative numbers and 0 { -4,-2,0,12,1} 13 13 Pass Pass at once, prove positive negative number 0 algorithm normal

                                                           ,         &NB Sp                          ,         &NB Sp                          ,         &NB Sp                          ,         &NB Sp                          ,         &NB Sp                     October 9, 2016 Sunday     

Cheng Hao

   

How to unit test with eclipse

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.