Test (self-production) in extreme programming

xiaoxiao2021-03-06  41

Software test and debugging technology research

0124080 Zhang Mingquan

This paper discusses discussion on the Extreme Programming, referred to as an Extreme Programming, referred to as the Extreme Programming, and combines the software test and debugging application in combination with the project. Extreme Programming is a lightweight development method encoding a core task, which will exist in each stage in the software development life cycle in code. Extreme programming is an extremely strict development method, its focus is in code review, frequent testing, customer participation, quick feedback, continuous reconstruction, refining framework, sustainable integration to design and reallo Design, there is a continuous plan. The four major values ​​of extreme programming have to be mentioned, four major value: communication, simple, feedback, courage. They are the wine that attracts people. Five principles: Provide fast feedback, simple assumption, manufacturing incremental change, inclusive change, warranty work. These are the principles of worship.

This article uses JUnit, CACTUS, HTTPUNIT, JMETER, JUNITPER, and combines Ant to detail the full-scale testing process in the pre-programming. From the name, you can see that JUnit is used for unit testing. CACTUS is used for container service testing. HTTPUNIT is used for functional testing. JMeter is used for application performance testing. JUnitPerf is used to carry out load tests.

First, discussion

Maybe you have not written true tests in the university campus project, and the test is the steps that must be unable to do. If you don't test, how do you determine how a function can run properly? If you don't test, how do you know that the code will still run after changing?

Write the code or write the test first, maybe you have not considered this problem. In extreme programming, write test is a recommended policy. If you write a test first, then the work of writing code will be easier, because you have already do what you should do, how to do it. Below we will discuss the characteristics of test tools.

JUnit unit test

In order to prove that the program code can work, some people use system.out.println () to monitor their program code. This approach has three problems: rolling blindness, subjectivity and lack of automation. This method may be effective at this moment, but over time, it is possible to fail. After a period of time, you have forgot their significance and become a useless part of the program.

JUnit's motto is: Keep The Bar Green To Keep The Cade Clean, as shown below: When

When the column in the figure, when there is no error, the test passes, the code is correct.

The user's test class must inherit the TestCase or TestSuite of JUnit. There are several ways to inherit the parent class, that is, setup (), Teardown (), initialization variable in setup (), release the test during Teardown () Resources. Like ASSERT in the C language, JUnit mainly uses Assert as a prefix to test whether it is successful. ASSERTEQUALS (), AssertNotnull (), assertnotsame (), assertnull (), assertsame (), asserttrue ().

CACTUS container service test

CACTUS's framework tool is used to test J2EE code, we have done unit testing, but there is no code to exist in vacuum, only unit test is not enough. We already have tools for isolating the simulation objects and integrated tests, but J2EE is so serious for container services, and there is no smoke test with the deployment container interactive (Smoke Test) will carry the project carrier Major risks. CACTUS provides a servlet, JSP custom tag, and Servlet Filters (filters), which support access to objects such as HTTPSERVLETREQUEST, PAGECONTEXT, and FILTERCHAIN ​​objects. At the same time, CACTUS is an extension of JUnit and inherits the JUnit test class.

HTTPUNIT functional test

HTTPUNIT's functional test, or a black box test, does not test the segment of the program code, but instead inquire about the web server and check the received response. Testing the entire web application is a fearful task, there are many different user behavior combinations, and try to repeat all of these user behavior is difficult, and HTTPUnit provides automation testing will undoubtedly reduce programmers. the amount.

HttpUnit can be seen as two functional groups:

l A maintenance state, providing a web client that transmits requests and reception response functions

l Simplify various methods for verifying the content of the response

In essence, httpunit is analog web browser, and HTTPUnit APIs can simulate many behaviors of the browser, including:

l form submission

l JavaScript

l HTTP certification

l cookie

JMeter's performance test

In the design phase of the project, we will get a series of important performance standard requirements, such as the system running hardware platform, the number of supported destination, etc. We cannot start performing performance testing at the end of the project, and we should gradually establish a tracking method to determine the bottleneck of the system.

JMeter is able to load tests and perform performance tests for HTTP, FTP, and RDBMS supported by Java database. JMeter can be used to test system performance under different loads, such as a large number of updates, a large number of browsing operations, a lot of transaction processing, or work in different load combinations, you can get visualized from his charts and tooth lines. Performance feedback.

JUnitper's load test

In any project planning phase, you must give the system performance standard after the project is completed. You can determine the current system to achieve performance standards by using JunitPer to decorate the existing JUnit test case.

There are two main test types in Junitper: Timed Test and Load Test, which are defined in the TimedTest class and the LoadTest class, which will be used later.

Second, the application in practice

Unit test using JUnit

As mentioned in the discussion, the user's test class must inherit the TestCase or TestSuite class, where TestCase is used for a single test, TestSuite is used for multiple tests (similar to the Vector structure)

Use JUnit test in Eclipse

The file used is from the JUnit test case. Below is a summary:

Package junit.sample;

Import junit.framework. *;

/ **

* Testsuite That Runs All The Sample Tests

*

* /

Public class alltests {

Public static void main (String [] args) {

Junit.textui.teStrunner.run (suite ());}

Public static test suite () {

TestSuite Suite = New Testsuite ("All Junit Tests");

Suite.addtest (vectortest.suite ());

Suite.Addtest (New TestSuite (JUnit.Samples.money.moneyTest.class);

Suite.Addtest (junit.tests.alltests.suite ());

Return suite;

}

}

Container service test using CACTUS

Users need to inherit servlettestcase and test the test class. As follows:

Test class SampleServlet.java

Import javax.servlet.http.httpservlet;

Import javax.servlet.http.httpservletRequest;

Public Class SampleServlet Extends httpservlet

{

Public void savetosesis (httpservletRequest request)

{

String Testparam = Request.getParameter ("TestParam");

Request.getSession (). SetAttribute ("Testattribute", TestParam);

}

}

Test class TestsampleServlet.java

Import junit.framework.test;

Import junit.framework.testsuite;

Import org.apache.cactus.servlettestcase;

Import org.apache.cactus.WebRequest;

Public Class TestsampleServlet Extends Servlettestcase

{

Public TestsampleServlet (String thename)

{

Super (thename);

}

Public Static Test Suite ()

{

Return New TestSuite (TestsampleServlet.class);

}

Public Void BeginsavetoseessionOk (WebRequest WebRequest)

{

WebRequest.addparameter ("TestParam", "IT Works!");

}

Public void testsavetoseession ionok ()

{

SampleServlet servlet = new SampleServlet ();

servlet.savetosesis (Request);

Assertequals ("IT Works!", Session.getattribute ("testattribute");

}

}

The results of the test can be displayed in XML format or displayed in web form. As shown below:

XML format

HTML format

Function test using HTTPUnit

Landing verification required to pay attention to each web program

Test target verify that the user is successful

Testing process

1. Enter the page address of the login address to verify that the page can be accessed normally.

2. Verify that the accessed page is the login page.

3, enter illegal username, password, verify the login failed.

4, enter the legal username, password, verify that the login is successful.

First write a test interface, named logintestinfo:

Publicinterface logintestinfo {

Public void testvalidpage () throws exception;

Public void testisloginpage () throws exception;

Public void testbadlogin () throws exception

Public void testgoodlogin () throws exception;

}

Implement a JUnit TestCase and the imports logintestinfo interface:

Import java.net.URL;

Import junit.framework.testcase;

Import junit.framework.testsuite;

Import junit.textui.teestrunner; import com.meterware.httpUnit.webconversation;

Import com.meterware.httpUnit.WebRequest;

Import com.meterware.httpUnit.WebResponse;

Import com.meterware.httpUnit.Webform;

Import com.meterware.httpUnit.getMethodWebRequest;

Public class logintest extends Testcase IMPLEments LogintestInfo {

Private WebConversation Browser;

PRIVATE WebRequest Request;

Private WebResponse Response;

Private string url = "http: // localhost: 8080 / index.html";

Public void setup () throws exception {

Browser = new WebConVersation ();

Request = New GetMethodWebRequest (URL);

Response = Browser.getResponse (Request);

}

/ / Enter the page address of the login address to verify that the page can be accessed normally

Public void testvalidpage () throws exception {

AssertNotnull ("LocalHost does not exist in the network!", response);

}

// Verify that the page accessed is logged in page

Public void testisloginpage () throws exception {

URL CurrentURL = response.geturl ();

String currenturlstr = currenturl.getProtocol () ": //" CurrentURL.Gethost () currenturl.getpath ();

Assertequals ("Login page is not localhost home!", CurrentURLSTR, URL);

}

/ / Enter illegal username, password, verify that the login failed

Public void testbadlogin () throws exception {

Webform form = response.getforms () [0];

Form.SetParameter ("UserName", "Baduser");

Form.SetParameter ("Password", "Bad");

Request = form.getRequest ();

Response = Browser.getResponse (Request); AssertTrue ("Your username and password are not filed in localhost!", response.getText (). Indexof ("localhost")! = -1);

}

// Enter the legal username, password, verify that the login is successful

Public void testgoodlogin () throws exception {

Webform form = response.getforms () [0];

Form.SetParameter ("UserName", "smile_xunn");

Form.SetParameter ("Password", "**********"); // The real password needs to be filled in here

Request = form.getRequest ();

Response = Browser.getResponse (Request);

Asserttrue ("Go to 'LocalHost' Network Failure!", response.gettext (). Indexof ("localhost")! = -1);

}

Public static testsuite suite () {

Return New TestSuite (Logintest.class);

}

Public static void main (string args []) {

Testrunner.run (suite ());

}

}

If your code quality is high, this test can pass, the following information appears:

.... TIME: 7.203

OK (4 tests)

JMeter's performance test

The above is part of the JMeter's interface, limited to space, specific use can refer to the Apache website.

JUnitPerf load test

In this test, all the methods described above can be integrated, and all put all in one. JUnitPerf works with existing JUnit tests. If you have performance requirements for a particular code, create a JUnitPerf test to test your code in line with standards and make sure that the code is still compliant after you reconstruct the code.

Third, conclusion

Through the above test, I want to pay the user in your product, you must take a chest and say: We are the best, all of which have proven. Whether it is an extension or function of the project, with the help of these tools, it will not be terrible, the larger the snowball.

As a faithful advocator of technology-first theory, I think the success of a test framework must be assessed after the user's use. Theory must be confirmed by practice, and the above tests provide technical descriptions of the software engineering courses and software practices in our company. As an open source project, maybe the above test framework has some drawbacks, and believe that under the inspiration of the open source spirit, it will be more beautiful.

Fourth, reference

1. Java Tools for Extreme Programming Written by Richard Hightower Nicholas Lesiecki Copy Right John Wiley & Sons Inc 2002.

2. Apache organizes Jakarta project documentation (including Ant, Junit, Cactus, HttpUnit, Jmeter, Junitper).

转载请注明原文地址:https://www.9cbs.com/read-73509.html

New Post(0)