• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Testing Options in Java
 

Testing Options in Java

on

  • 2,843 views

A J2EE Testing presentation I did for RMOUG, Aug2007 Rmoug 2nd Qty Mtg

A J2EE Testing presentation I did for RMOUG, Aug2007 Rmoug 2nd Qty Mtg

Statistics

Views

Total Views
2,843
Views on SlideShare
2,838
Embed Views
5

Actions

Likes
1
Downloads
38
Comments
0

3 Embeds 5

http://www.linkedin.com 3
http://webcache.googleusercontent.com 1
http://www.slideshare.net 1

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

    Testing Options in Java Testing Options in Java Presentation Transcript

    • Testing Options in Oracle ADF Michael A. Fons Graebel Companies, Inc. August 2007
    • Introduction
      • I have been working as an Oracle developer for 17 years.
        • My daily work has mostly involved PL/SQL, web technolgies, Forms, Reports, …
      • Java in my career
        • I have spent off-hours for the last 2.5 years working with JDeveloper and ADF (and have tried to get more involved with Java technologies for the last 7 years).
        • Nevertheless, J2EE testing and development methodologies sometimes feel foreign to me.
      • For this presentation…
        • I have spent the last 3 months (after work) trying to learn all I can about testing Java programs and ADF applications.
        • I hope my perspective helps many people in this transitional time for Oracle developers.
    • Outline
      • Topics
        • What does Oracle offer to test ADF/J2EE app?
        • Different sorts of products available to help test?
      • This presentation is a survey of some software products which work (or not) with ADF Faces/JSF/ADF BC
    • Planned Demos (using JDev 10.1.3.2)
      • Test some model components using JUnit test cases.
      • Run a JUnit test script in using Ant automation.
      • Some “view-” (container-) level (black box/end-to-end) testing
      • Some other test products that work with ADF, for different testing purposes.
    • Testing an ADF Application
      • Research J2EE testing types
        • Unit/Object/Code Logic testing – is the app built correctly? [1] (It is a best practice to provide a test class for every class you develop for a project.)
        • End-to-end/Functional testing – did you build the right features into your app to satisfy the end users’ need(s)? [1]
        • Integration (with J2EE container) testing
        • Regression/System Integration testing.
        • Load/Speed testing
    • JDeveloper testing basics
      • JDeveloper primarily offers and promotes testing of the model layer using…
        • JUnit – to run test scenarios on model components
        • Ant – to help automate testing runs
      • Another feature you can use for model level testing includes…
        • ADF has easy read/write of (test) bulk data using XML. (ViewObjects and Rows have readXML and writeXML methods.)
    • JUnit basics
      • What is JUnit?
        • A basic unit test framework for Java (hence, “J”-Unit).
        • Very popular; very widely ported
          • C#,
          • Python,
          • Fortran,
          • Perl,
          • C++,
          • JavaScript [4]
        • Many sources referenced XP/XM (eXtreme Programming/Modeling in conjunction with JUnit)
        • Often the foundation of many other testing programs/paradigms
    • JUnit basics (continued)
      • Components
        • TestCase -- it is a class you can extend which contains methods which test for particular business rule being implemented effectively or not.
        • TestSuite – is a class which runs a set of TestCases. (these cases can be specified explicitly or auto-detected)
        • TestFixture -- [9] “…a set of objects, having known values, that provide data for the test cases. Any class can serve as a test fixture…”. In this case, JDeveloper TestSuite wizard create a test fixture that gets the Application Module you need to test your ADF BC data.
    • Ant basics
      • Head, Thorax, Abdomen, six legs…no…not that kind of ant…
      • Ant is like “make”…only better. (Dependency management, XML-based, extendable, etc.)
      • Ant is often used in automating compiling programs.
      • In this context of this presentation, it automates batch processing JUnit Tests.
      • JDeveloper can create (Under General  Ant  Buildfile from Project) an Ant buildfile.
        • Still needs a lot of work, though, to get it working with JUnit and an ADF app.
        • Best to emulate SRDemo build.xml file.
      • When your ant build.xml (buildScript) is integrated with JUnit and running correctly for you…really neat log of testing results.
    • JUnit/Ant Installation
      • Run “Check for updates”, under Help menu.
        • Will need to login using Technet username and password
        • Download and install anything having to do with Ant or JUnit (include the extensions downloads catagory).
      • Installing Ant will update your DOS PATH variable (so you will be able to run Ant in a “batch” file).
      • Type “ant -?” on command line for some help.
      • You can learn more, when you set Ant options (in or out of JDev) to be in “verbose” or “debug” mode.
      • Perhaps better to kick off Ant jobs from within JDeveloper; much less complex than maintaining a command file.
      • I do not yet know of a simple way to see what you would need to run on a command line to run this job in the middle of the night, say. I experimented with –lib switch, but event then there was still something missing.
    • JUnit TestCase Class
      • To create a test case, extend JUnit TestCase class
      • Contains many “assert*” methods (and also “fail”).
        • Examples:
          • assertEquals – must find equality between first parameter and second or assertion fails.
          • assertTrue – boolean value of parameter must be true or the assertion fails
      • Test methods’
        • names must have naming convention “test*”
        • If any assert* calls in this method fail, then the outcome of your test method is failure as well.
        • If all assert* calls succeed, then the outcome of your test is success.
    • JUnit: To Test any Pre-existing Method…
      • Select the Java program in Application Navigator
      • Select method to test in Structure Pane.
      • Right-click to get context menu.
      • Click on “New Method test…”
      • Select Create or Add to TestCase Class; fill in other fields as appropriate and submit your changes.
      • (Note: this does not work with a constructor “method”; “New Method test…” will not be on the context menu in this case.)
    • JUnit: Create a TestCase for a Method
      • Right-click on the project the method’s class is in.
      • Click New…
      • Under the General category, select the Test Case item, and click OK.
      • In the wizard,
        • Page 1 (optional), either select your class from the dropdown list, or use the Browse… button to find your class in the appropriate package hierarchy.
        • Page 2, adjust field values as needed. Be careful about the package name; JDev seems to prefix your current package with “test.”. If you do not notice this you will have to refactor (move) your test case to get it into the package you intended.
        • Page 3 (optional), specify a test fixture if needed.
    • Running a Test Case
      • In JDeveloper you can run this test case class using the Run… context (right-click) menu command.
        • This opens a JUnit Test Runner Window in JDeveloper;
        • your TestCase(s) are then run,
        • and the results are shown in the window.
    • Demo 1
      • Test some model components using JUnit test cases (using test-first approach).
        • Create a TestSuite for an application
        • Add a test case for an unimplemented business rule to one of the TestCase classes.
        • Run the test; watch the failure.
        • Implement the business rule.
        • Run the test again; watch it succeed.
    • Demo 2
      • Run a JUnit test script in using Ant automation.
        • This was adapted from SRDemo.
        • If you need a copy of the Ant build script so you can adapt it, email me (mfons@graebel.com). Or you can study SRDemo’s…somewhat challenging, for me.
        • Be careful about the way they define ${jdeveloper.home}. It appears that in some places in the build this does not translate and causes the test build not to run.
        • Command line: ??? seems difficult…
        • Cool output log in output directory.
    • Testing tools…
      • Fit (command line)/FitNesse (GUI interface) -- claims “collaboration and communication” through color-coded presentation of testing results – comparing customer’s expecte results with your program’s actual results; implemented on a variety of platforms [12]
      • StrutsTestCase – tests outside the app server with mock-objects
      • ServletUnit – simulates a Servlet container; alternative to mock-objects.
      • XMLUnit – tests different aspects of XML files.
      • Cactus – tests inside Servlet container
    • …more tools…
      • More tools
        • HtmlUnit (GargoyleSoftware.com) – page flow tests, other view-level tests. Worked fine with ADF. Integrates with JUnit. ( http:// htmlunit.sourceforge.net/gettingStarted.html )
        • HttpUnit (not the same as HtmlUnit) – has a few issues with ADF, apparently. May or may not have problems “playing well with Cactus”.
        • Diasparsoft Toolkit – creates fake Servlet requests, and other things.
        • Selenium IDE ( http://www.openqa.org/selenium-ide / ) – creates test classes during page navigation.
        • Mauve?? – a free suite of functional, blackbox test for the core Java™ libraries. [11] Actually I am not sure about this one
    • End-to-end testing
      • Recreated Julien Dubois’s scenarios [5].
        • Put his examples together fairly rapidly
        • Uses JUnit with Cactus and StrutsTestCase
        • Does the same test with JUnit and HttpUnit (Note: for HttpUnit, make sure to manually start your embedded OC4J since you are not doing a “Run” on a web page, actually running your app.)
    • End-to-end testing
      • Challenges:
        • HttpUnit -- had a problem clicking ADF Faces link/button implementations, like: <a href=&quot;#&quot; id=&quot;myform:theSubmitButton&quot; onclick=&quot;submitForm('myform',1,{source:'myform:theSubmitButton'});return false;&quot;>
        • this causes an conversion error in the call to a org.mozilla.javascript function.
    • Demo 3
      • Some End-to-end testing
        • With HttpUnit/HtmlUnit –
        • With Cactus –
        • Compare approaches
          • HttpUnit/HtmlUnit pretends to be a browser, so (as such) it can generate requests and receive responses.
          • Cactus actually runs JUnit tests inside the OC4J. You set up one or two Cactus servlets as part of Cactus setup.
    • Demo 4
      • Some other test products that work with JDeveloper.
        • Fit – simplest example: arithmetic; lots of potential (that I don’t quite have a grip on yet)
        • XMLUnit – can tell you…
          • XML file diff
          • XML validation
          • Shows projected outcome of XSLT transformation or an XPath evaluation.
        • Selenium IDE –
          • extension to Firefox; file download can be run using firefox exe; ADF Faces will run using firefox if firefox is your default browser.
          • Can record and play-back keystrokes.
          • Very easy to use.
          • Also has a browser-based test-runner.
    • Other kinds of testing
      • Performance/Load/Stress/Scalability/Speed testing [6]
        • JMeter
        • The Grinder 3 – workers, agents, console…repeat tests just like many people were doing the test over and over from many different machines. Ported to many computers.
        • Load test tools on Mercury?
        • For EJB apps: Bean-test, EJBQuickTest[7]
        • JStyle – critiques Java code style (including some code metrics) [7]
        • JTest – supports a variety of tests[7]
        • JProbe – profiler/memory debugger[7]
      • DbUnit –
        • JUnit Extensions
        • Puts database into a known state between tests
        • Can Import/Export XML datasets, even very large datasets.
    • Demo 5
      • Speed testing
        • The Grinder 3 – now allows you to write in Jython. (I assume this is a good thing; Grinder-people seemed excited about it.)
        • JMeter – Apache desktop application
          • Can be used to test files, Servlets, Perl scripts, Java Objects, Databases, FTP servers, …
    • Zero-product testing
      • “Horrors! No testing software?”
      • Remember: it is possible to just let your users take the software for a spin, and get back to you…
    • Questions?
      • This presentation will be published in the next week or so at the www.rmoug.org website.
      • If you have any later contact me at [email_address] ...
      • Or try out the JDev forums on technet.oracle.com…good stuff.
        • Helpful people
        • Knowledgeable people
        • Some Oracle JDeveloper Developers monitor this and other forums. (Steve Muench, Shay Shmeltzer, et al ).
    • Resources
      • “ Testing J2EE Applications” http://www.javaworld.com/javaworld/jw-08-2004/jw-0830-testing.html?page=1
      • “ CVS, Ant, and Junit with JDeveloper” http://www.oracle.com/technology/products/jdev/101/viewlets/101/agile_development_viewlet_swf.html
      • Download JDeveloper extensions: JDev Ant Task, JUnit Integration, JUnit Integration for Business Components, JUnit Integration for JDBC.
      • Wikipedia: http://en.wikipedia.org/wiki/JUnit
      • “ In-container Testing with JUnit”, Julien Dubois, http://www.oracle.com/technology/pub/articles/server_side_unit_tests.html
      • Steve Muench in JDev Technet forum: http://forums.oracle.com/forums/thread.jspa?mesageID=1944932&#1944932
      • Dr. Dobb’s: “A J2EE Testing Primer” – (2001) http://www.ddj.com/dept/architect/184414736?cid=Ambysoft
      • Httpunit home: http://httpunit.sourceforge.net/doc/tutorial/index.html
      • “ Unit Testing with JUnit” – part of JUnit extension in JDeveloper 10.1.3.2
      • Shay Shmeltzer’s blog – http://blogs.oracle.com/shay/2007/08/09#a495
      • Mauve Project – http://sourceware.org/mauve
      • Fit – http://fit.c2.com/
      • Example on htmlunit workin for ADF Faces example: http://saloon.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb =get_topic&f=82&t=001139
      • Selenium IDE – http://www.openqa.org/selenium-ide/download.action
      • The Grinder – http://grinder.sourceforge.net/
      • XMLUnit -- http://xmlunit.sourceforge.net/
      • DBUnit – http://dbunit.sourceforge.net/
      • JMeter – http://jakarta.apache.org/jmeter/
      • Unit Testing with Mock Objects – http://www.ibm.com/developerworks/library/j-mocktest.html