test strategy for web development

35
Test Strategy for web development

Upload: alice-yang

Post on 26-May-2015

1.564 views

Category:

Technology


6 download

TRANSCRIPT

Page 1: Test strategy for web development

Test Strategyfor web development

Page 2: Test strategy for web development

Comparison of costs to fix defects at different stages

Page 3: Test strategy for web development

Static Analysis really useful?

• Static analysis, at best, might catch 5-10% of your software quality problems

• Used effectively, static analysis is cheaper than other techniques for catching the same bugs

Page 4: Test strategy for web development

Code Analysis Strategy

• Code Static Analysis tool review source code

• Static Analysis and Data Flow Analysis Tool review byte code

• Automate build and code review process

• Continuous Integration

Page 5: Test strategy for web development

Static Analysis tool

• Commercial product : Parasoft Jtest

Open source tool:

For Java• CheckStyle• PMD• FindBugs

For JavaScript• JavaScript Lint

Page 6: Test strategy for web development

What is FindBugs

• FindBugs uses the Apache BCEL library to analyze the classes in your application and detect potential bugs.

• FindBugs rules (or "detectors") use a variety of inspection techniques, from examining the structure of the class right through to studying the detailed dataflow through the class.

Page 7: Test strategy for web development

FindBugs in ActionFindBugs is an open source static analysis tool, developed at the

University of Maryland

Looks for bug patterns, inspired by real problems in real code

Held FindBugs fixit at Google May 13-14th, 2009• 300 engineers provided 8,000 reviews of 4,000 issues • 75+% were marked should fix or must fix

more than 1,500 of the issues have already been removed

Page 8: Test strategy for web development

How to use FindBugs

Page 9: Test strategy for web development

JavaScript Lint

• Based on the JavaScript engine for the Firefox Browser

• check JavaScript source code for common mistakes without actually running the script or opening the web page.

Page 10: Test strategy for web development

Front end AJAX(JQuery) Application

Page 11: Test strategy for web development

Front end work procedure

• Clients in web browser (JQuery Ajax) send Asynchronous Http requests to server side

• jQuery Ajax get callback response with Json format.

• The JavaScript code parse JSON and change the content of webpage.

Page 12: Test strategy for web development

“Distributed” Model-View-Controller

HTTP Request (GET or POST)

DHTML Reply (new page/script)

RequestHandlers

WorkspaceJSP

Templates

Server

Engines

JQueryController

DHTMLView

Browser

JSON (DOM)Model

JSON Reply (new model/data)

Page 13: Test strategy for web development

Testing Strategy

• Test Data Handler and Data Source

• Test JavaScript

• Automate UI Tests

Page 14: Test strategy for web development

Choose Testing Tools

Qunit JsunitGeneral JS Yes YesAjax Yes Hard to say Cross Platform Yes YesDeveloper No 10 more 1Who use Google, MS,Yahoo Yahoo Discuss Area Active Active Advance New A little oldCruise control Yes Yes

Page 15: Test strategy for web development

Qunit for JavaScript Testing

• Choose Qunit testing for JavaScript function. Use web browser to run Qunit testing

• The JavaScript function includes two parts: – general function just like creating URL, validate input

data format.

– Ajax call, get JSON from server and parse the JSON.

Page 16: Test strategy for web development

Proof of Concept for Qunit

• Focus on JavaScript function in one page check out project.

Problem: a lot of functions are private.

Resolution: refractor code. Use public return method to change private to public.

Page 17: Test strategy for web development

Proof of Concept for Qunit

Problem: In JavaScript source code, use JavaScript execute pattern. Once the Java script function loaded, it is already executed. In some cases, the results have been changed.

Resolution: refractor code. Comments off that execute parentheses in the function end. Let test function execute it.

Page 18: Test strategy for web development

Proof of Concept for Qunit

Problem: Ajax call is asynchronous. Hard to know when it is finished, we can get data.

Resolution: One method is to change the asynchronous call to synchronous.

The alternative method is still to keep the asynchronous call, use Qunit’s stop() start() pattern. Use asynchronous callback to start test method after asynchronous call ending.

We choose the second method.

Page 19: Test strategy for web development

Proof of Concept for Qunit

Problem: Ajax call is executed with variable number parameters which is changed with situation. Test method hardly get Callback function data parameter.

Resolution: If it is necessary to test, pull out tested Ajax call function, separate to different cases, and fix the parameter number.

Page 20: Test strategy for web development

AJAX function example function getBag(callback) { jQuery.ajax({

url: "ajax/saksbag.json", type: "POST", data: "bmForm=initialize_saks_bag_service", dataType: "json", timeout: 2700, success: function(response) {

callback(response); },

}); }

Page 21: Test strategy for web development

Qunit AJAX testtest('test getBag AJAX', function () { expect(1); stop(); getBag( function(response) {

equals(response["continueShoppingLink"], "http://dev5.saksdirect.com/Entry.jsp?ASSORTMENT%3C%3East_id=1408474399545537&bmUID=1249578208442");

start(); } )});

Page 22: Test strategy for web development

Web Browser Launch Qunit test cases

Page 23: Test strategy for web development

How to test Data Source

• For JSON test, one method is to unit test server side Java code who produce JSON

• Write JUnit test cases to test these server side java classes.

• The alternative method is to verify the JSON from client side.

• The JSON component is sent back by the call back function. With selenium, we can catch JSON component from intended web page and make sure the data accuracy. This also can prove the JSON transmission right

Page 24: Test strategy for web development

Use Selenium RC to do UI automatic testing

• Export the recorded test cases to Java code. With RC mode to run these test cases. So we can run these test cases in Cruise control.

• The web application group has already done part of work previously. We need to recover previous work and continue to do new work.

• Combined Selenium RC and HTMLUnit, we can implement some AJAX based UI tests and enhance the test speed. This is the conception of Selenium 2.0 which will be released recently.

Page 25: Test strategy for web development

Selenium 2.0 (WebDriver)

• Mult-browser testing including improved functionality for browsers not well-supported by Selenium-1.0.

• Handling multiple frames, multiple browser windows, popups, and alerts.

• Page navigation and Drag-and-drop. • HTMLUnit driver improve testing speed.• AJAX-based UI elements.

Page 26: Test strategy for web development

Example for Selenium catching bugs

• Test case: Sending a billing address, set this billing address as a shipping address.

• Billing address is successfully saved. • Test response JSON said shipping

address list is still null, billing address not be set as a shipping address, failed test.

Page 27: Test strategy for web development

In container testing

• Best way of resolving JUnit test difficult for BM application is to use in container testing framework to wrap Junit test case

• Running JUnit test cases in BM environment is a typical application of container integration unit testing in J2EE.

• JunitEE and Cactus are two popular tools for integration unit test

Page 28: Test strategy for web development

JunitEE

Page 29: Test strategy for web development

JunitEE TestRunner

Page 30: Test strategy for web development

Test Code Example: Get config DNA from BM API

protected void setUp() throws Exception {

super.setUp();

//JUnit need to set up a DNA configuration by reading a DNA file

//final DNAList dna = DNAList.readDNAFile("dna/config/custom/payment.dna");

//JUnitEE directly get DNA configuration from BM environment

final DNAList dna = BMContext.getConfig("payment.dna");

creditCardDropDown = new CreditCardDropDown(dna);

}

public void testShouldReturnCCD() {

java.util.List list = creditCardDropDown.loadDomainsListfor("CCD");

assertNotNull(list);

assertTrue(list.size() > 4);

DropDownElement dropDownElement = (DropDownElement) list.get(0);

assertEquals("Choose a Card", dropDownElement.getDisplay());

dropDownElement = (DropDownElement) list.get(1);

assertEquals("SAKS", dropDownElement.getValue());

…..

}

Page 31: Test strategy for web development

Automated Testing of Web Service with SoapUI

• Testing purpose is testing application code, not to direct to test Web service itself

• If the Web Service is not available, SoapUI can delivery a Mock web service to solve the unit testing dependency

Page 32: Test strategy for web development

SoapUI procedure

• Input WSDL• Generate request and response xml

template• Create a a Mock Web service based on

WSDL• If Junit test case call Mock Web Service, it

will return Mock response• XMLUnit can be used to verify response

XML

Page 33: Test strategy for web development

SoapUI mock web service

Page 34: Test strategy for web development

Continuous Integration

• Based on existed Cruise Control Server, continue to use it as continue integration Server.

• The current Cruise Control implements automatically build Projects.

Page 35: Test strategy for web development

Continuous Integration

• Apply JUnit and JUnitEE to test server side java code.

• Use QUnit to test JavaScript• Use HTMLUnit to verify JSON• Use selenium RC code to do automatic UI

testing• Implement automatic test function on the

cruise control.