Eclipse Plug-in Continuous Testing introduction

Source: Internet
Author: User
Tags add arrays integer new features
introduce

Now more than ever, it developers are concerned about the importance of testing, and the lack of well tested code is more likely to be problematic. In extreme programming, test-driven development has proven to be an effective way to improve software quality. In the test-driven development approach, the software engineer writes the test code first before writing the functional code, which guarantees the correctness of the program's code from the very beginning, and is able to automate regression testing every time the program evolves.

Unit tests are the types of tests that are most closely related to the developer. It is usually written and executed by developers. Because unit tests often occur shortly after an error has occurred, the cost of finding errors through unit tests and then correcting them is usually relatively small. Unit testing is so important that some extreme programming enthusiasts advocate that any untested code should be automatically deleted. JUnit is the de facto standard of unit testing for Java developers. Despite the more sophisticated testing tools such as testng and JTiger, JUnit is still the head of the test tool.

One evidence of JUnit's dominance of the market is that there are currently many extensions and Plug-ins developed for JUnit. What we're going to talk about today is a eclipse plug-in continuous testing with JUnit. It can perform tests using the machine's idle calculation cycle and display it as an error in the problem view and editor's markup area.

Performing tests during the idle time of writing code consumes some CPU time and other resources. But we don't need to be preoccupied with the benefits of continuous testing. Remember the first time you used incremental compilation of Eclipse?

I remember being dismissive of this feature, and now I have relied entirely on incremental compilation to correct my occasional grammatical errors. For software developers, any tool that can effectively shorten the write-compile-test-modify cycle is of great significance. In this regard, I believe that continuous testing is of great significance for software developers. On the http://www.eclipse-plugins.info/we can see that continuous testing is well received by many users

Install continuous testing

The method of installing continuous testing in Eclipse is very simple, similar to installing other plugin methods. First we start Eclipse3.1, click menu Items Help->software update->find and Install. In the Pop-up wizard dialog, we select "Search new Features to Install" and click "New Remote Site" In the pop-up dialog box, as shown in Figure 1. Enter Http://beust.com/eclipse in the URL and click "OK". As shown in Figure 1, by clicking Finish, Eclipse will help us add a site for update. The reader who is familiar with eclipse must not be unfamiliar with the process.

Figure 1 New update Site

After you add the update site, select the update site that you just added in the Install dialog box that appears, and press the Finish button, as shown in Figure 2. After the subsequent download and confirmation, we have installed the continuous testing.

Figure 2 Installing continuous testing

After the continuous testing has been installed in the project continuous testing, we can activate continuous testing in any Java project. Right-click in the package views and select property from the menu. In the subsequent Engineering Properties dialog box, we can see that the configuration information has a new taxonomy continuous testing. Select this category and choose Enable informed testing and enable continuous testing in the continuous testing Properties page. So we activate the continuous testing.

Figure 3 Configuring Continuous testing

In this dialog box, we can also configure some of the continuous testing settings information. For example, find the strategy for test case, prioritize settings for testing, and filter before the test starts. For example, I like to let continuous testing first test for recent errors.

Views provided by continuous testing

Next, we create a new test case in a project that activates continuous testing. As you can see, our test case does not contain any useful tests. The two test methods that we offer are one that is bound to fail, and the other throws an exception. With this example, we can see what continuous testing has to offer us.

Package test;

Import Java.util.Arrays;

Import Junit.framework.TestCase;

public class Dummytest extends TestCase {
public void testtopthreeintsunsorted () {
Integer one = new integer (1);
Integer two = new Integer (2);
Integer three = new Integer (3);
Integer four = new integer (4);
Integer five = new integer (5);
Integer six = new integer (6);

Assertequals (Arrays.aslist (new integer[] {One, two, three}), Arrays
. Aslist (New integer[] {Four, five, six}));
}

public void TestException () throws Exception {
throw new IllegalArgumentException ();
}
}

The continuous testing plug-in executes the test code in the background, and continuous testing will notify the developer by problem view when there are errors or anomalies detected. In the test cases we provide, Problem view will look like the following:

Figure 4 Problem View

If we double-click a test error message in Problem view, the Java Editor opens and displays the test method that generated the error. It's very much like the way we look at other mistakes, doesn't it? In addition, if we open the Dummytest.java in the editor, we can also see that the new test error tag appears on the left-hand side of the editor.


Figure 5 Test error mark on the editor

As we can see from the above description, the way to use continuous testing is very simple. The continuous testing plugin did not even introduce any new views. We work in exactly the same way as ever, and the only difference is that now eclipse automatically displays test error messages in the IDE.

Support for multiple project

When using JUnit for testing, we usually place the test in a separate project. In this case, we need to do some special configuration of the project. If we put the test case of the Hello project in the engineering hello.test, then when we use continuous testing support for the Hello project, we need to configure the continuous testing attribute of the Hello project as shown in Figure 1.

Figure 6 Configuration test in multiple engineering scenarios

That is, we need to change the way continuous testing find the test case, so that when the Hello project is modified, continuous testing from the engineering hello.test.

In addition to multiple project support, continuous testing supports other advanced features such as HOWSWAP, low priority execution, remote Executeon, and so on. Interested reader friends can further study it.

Summary

By using continuous testing, we are able to check the logic correctness of the code while modifying the code. If Eclipse's incremental compilation capabilities allow us to gain confidence in the correctness of the code's syntax while modifying the code, continuous testing can help us gain confidence in the correctness of the code's logic. The combination of the two will enable us to write fewer bugs in our software and, at the same time, minimize the cost of correcting errors.



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.