• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
View Presentation
 

View Presentation

on

  • 1,085 views

 

Statistics

Views

Total Views
1,085
Views on SlideShare
1,085
Embed Views
0

Actions

Likes
0
Downloads
3
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    View Presentation View Presentation Presentation Transcript

    • Testing Testing Testing
      • Joakim Björklund
      • Director of IT Services Division
      • Linköpings universitet
      • Sweden
    • Testing testing testing
      • “ You all know the need for testing, but how do you actually find time to do it? This presentation gives an outline on some of the tools you can use to perform testing of your Java application and save time while weeding out the bugs. The tools discussed include HttpUnit and Canoo.”
      • An odyssey of open source tools for testing.
    • Testing testing testing
      • Before we get started:
      • Get a good software testing book!
      • Go a course on testing at the Computer Science department!
      • Follow a software production model
      • Automate all testing!
      • Daily builds! (With testing and test reports)
      • Documentation (JavaDocs and Wiki)
    • Testing testing testing
      • Design patterns
      • Refactoring
      • Reusability
      • Don’t gold plate the code!
      • Spend a moment or two on system architecture
    • Testing Testing Testing
      • You all know the need for testing? Or do you?
      • When are you supposed to take the cost for testing? - During development or during system maintance?
      • Automated testing – take the time to save time!
      • When are your application done?!?
    • Testing Testing Testing
      • Testing is a bit more than:
      • System.out.println(“This works!”);
      • Debugger expressions
      • Small test scripts
    • “ Testing theory”
      • Testing can be done on several “layers” of the product being developed.
      • Unit testing – domain/application logic
      • Integration testing – APIs
      • Functional testing – acceptance, top-level
      • Performance testing – the need for speed
      • "Regression testing" is the concept of testing that asserts that everything that worked yesterday still works today
    • Automatic Testing
      • In order to decrease the cost, time and hassle during the testing phase, the first thing to consider is automatic testing.
      • ” If a program feature lacks an automated test, we assume it doesn’t work. This seems much safer than the prevailing assumption, that if a developer assures us a program feature works, then it works now and forever.”
      • Helps regression testing (or is a prerequisite)
    • Tools - mentioned
      • Testing tools
      • JUnit – unit testing
      • Cactus – unit/integration
      • Canoo – functional testing
      • HTTPunit – functional testing
      • JMeter – performance testing
      • Other useful tools
      • Ant – build tool
      • Bugzilla – bug tracking tool
    • Open Source vs Commercial
      • As you noticed all tools in this presentation is Open Source. One of the reasons for this is that the cost for the testing tool should not be an obstacle for the testing process itself.
      • Access to the source code…
    • Ant
      • Ant is a build tool that enables you to automate the build process.
      • Ant – in java for java
      • Build files in XML i.e. build.xml
      • Every build file contains one project element. A project element contains target elements. Each target consists of a set of task elements.
      • Many of the tools described in this presentation utilize Ant…
    • Ant
      • Example of targets:
      • Test – run the tests
      • Clean – Clean out the output directories
      • Deploy – Compile the JARs, WARs etc to a exec system
      • Publish – Output the source and binaries to any distribution site
      • All – Perform clean, fetch, build, test, docs and deploy
    • JUnit
      • JUnit is a framework for writing unit tests.
      • Test case = a related set of tests, typically every class should have a test case.
      • Test fixture – the resources needed to run the test
      • Test suite – a collection of related test cases.
    • JUnit
      • Subclass junit.framework.TestCase
      • If you need fixture objects, override the setUp() method.
      • Define a number of tests that return void and whose method name begin with test (testAdd(), testPut() etc)
      • If you need to release resources that where part of the fixture, override the tearDown() method
      • If needed define a suite of tests
    • JUnit
    • JUnit
      • To get xml-output from the test:
      • <target name=”test” depends=”compile”>
      • <junit printsummary=”true”>
      • <formatter type=”xml” />
      • <test name=”junit.samples.TEST”>
      • <classpath>
      • <pathelement location=”${outdir}” />
      • </classpath>
      • </junit>
      • </target>
      • JUnitreport – to generate WebPages of the result
    • Cactus
      • A tool for tests on servlets and other J2EE components.
      • Cactus provides ”redirectors”, which serve as points of entry to the container.
      • The redirectors execute test cases written for Cactus in the container and provide access to container objects (HttpServletRequest, PageContext etc)
      • Cactus integrates with JUnit
    • Example servlet Public class LiUServlet extends javax.servlet.http.HttpServlet { Public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException { Response.setContentType(”text/html”); PrintWriter writer=response.getWriter(); Writer.println(”<a href=’http://www.liu.se’>”); Writer.println(”Linköpings universitet</a>”); }}
    • Cactus Private LiUServlet servlet; Public void setUp() throws Exception { servlet = new LiUServlet(); servlet.init(config); } /** Test of doGet method **/ public void testDoGet() throws Exception { servlet.doGet(request, response); }
    • Cactus Public void endDoGet(com.meterware.httpunit.WebResponse response) throws Exception { WebLink link = response.getLinkWith(” Linköpings universitet”); assertNotNull(link); System.out.println(response.getText()); org.w3c.dom.Node = response.getDOM(); }
    • Canoo
      • Canoo is a web application testing suite.
      • Canoo is not restricted to only testing Java applications
      • Uses other Open Source packages (JUnit, JTidy)
      • Fairly easy to use, can the customer write tests?
    • Canoo
      • As usual a project tag
      • <project name=&quot;anstp&quot; basedir=&quot;.&quot; default=&quot;test&quot;>
      • Properties, esp canoo.dir
      • <property name=&quot;base.dir&quot; value=&quot;${basedir}&quot;/>
      • <property name=&quot;canoo.dir&quot; value=&quot;/service/canoo&quot;/>
      • <property file=&quot;${basedir}/../../../tomcat-src/local.properties&quot; />
      • <property file=&quot;${basedir}/../../../tomcat-src/webtest.properties&quot; />
    • Canoo
      • The following target is needed to call canoo:
      • <taskdef name=&quot;testSpec&quot; classname=&quot;com.canoo.webtest.ant.TestSpecificationTask&quot;>
      • <classpath>
      • <fileset dir=&quot;${canoo.dir}“ includes = &quot;**/lib/*.jar&quot;/>
      • </classpath>
      • </taskdef>
    • Canoo
      • Lastly the target for the testing itself
      • <target name=&quot;test&quot; >
      • Detta target ska innehålla tasken testSpec (med ett eventuellt name):
      • <testSpec name=“Template for Canoo tests&quot;>
      • In testSpec you need some config parameters:
      • <config host=&quot;${SERVER_HOST}&quot; port=&quot;${HTTP11_PORT}&quot; protocol=&quot;${SERVER_PROTOCOL}&quot; basepath=&quot;${SERVER_BASEPATH}&quot; verbose=&quot;${webtest.verbose}&quot; resultpath=&quot;${base.dir}&quot; resultfile=&quot;${webtest.resultfile}&quot; showhtmlparseroutput=&quot;${webtest.showhtmlparseroutput}&quot; summary=&quot;${webtest.summary}&quot; saveresponse=&quot;${webtest.saveresponse}&quot; />
    • Canoo
      • A suitable sequence of test steps
      • <steps> <!– test steps below -->
      • <invoke stepid=“Fetch start page&quot; url=&quot;render.uP&quot; />
      • <verifytitle stepid=“Verify page title&quot; text=&quot;Mitt LiU&quot; />
      • <setinputfield stepid=“Set username&quot; name=&quot;userName&quot; value=&quot;xgugro828&quot; />
      • <setinputfield stepid=“Set password&quot; name=&quot;password&quot; value=&quot;kisen&quot; />
      • <clickbutton stepid=“Press login button&quot; name=&quot;Login&quot; />
      • <verifytext stepid=“Verify that we came to Gusten Grodslukares start page in the portal&quot; text=&quot;/Gusten Grodslukare&quot; />
      • <!– Test steps above -->
      • </steps>
    • Canoo
      • Closing tags:
      • </testSpec>
      • </target>
      • </project>
    • HttpUnit
      • HttpUnit provides a Java framework for functional testing.
      • HttpUnit is a solid ground to build your tests on.
      • But it might comes with the price of duplication.
    • HttpUnit
      • WebResponse response = converstion.getResponse( http://codex.liu.se );
      • WebLink link = response.getLinkWith(” Linköpings universitet”);
      • WebRequest request = link.getRequest();
      • response = conversion.getResponse(request);
    • Performance
      • Performance: Number of simultaneous users, size of web pages returned...
      • “ the user experience” – It is the end users experience that are key to the application performance.
      • Locate the bottlenecks as early as possible – refactor and re-architect
    • JMeter
      • JMeter a 100% pure java desktop application.
      • Test: HTTP, FTP, RDBMS…
      • Extensible… write your own test
      • Simulate heavy load (application, server and network)
      • Gives instant visual feedback
    • JMeter
      • You must have a TestPlan
      • A TestPlan consists of one to many ThreadGroups.
      • A thread can be seen as a simulated user
      • A timer is added to a ThreadGroup (Constant, gaussian random, uniform random)
      • Controller
      • Listener
    • Bugzilla
      • http://www.bugzilla.org/
      • A bug-tracking tool, since naturally there will be bugs and there is an actual need to follow progress of the software.
      • Consider adding bugs automatically…
    • Bugzilla
    • Links
      • JUnit – http:// junit .org
      • Canoo – http:// webtest . canoo .com
      • HttpUnit - http:// httpunit . sourceforge .net
      • Bugzilla – http://www. bugzilla .org
      • Ant, Cactus, JMeter - http:// jakarta .apache.org
    • Summary
      • Automate the testing!
      • Testing is not rocket science
      • Include testing from the beginning
      • Use the web
    • Testing Testing Testing
      • Q & A
      • Joakim Björklund
      • [email_address]