Agile Development Using Jboss Seam Daniel Hinojosa Evolutionnext Programmer/Developer/Instructor 02/15/08
What is Agile Development? According to Wikipedia: It is a conceptual framework for software engineering that promotes development iterations throughout the life-cycle of the project. Each iteration includes development, testing, documentation, and a functioning working product after each iteration. Various Agile Methodologies out there Scrum, Crystal Clear, XP (Extreme Programming), Feature Driven Development, and more.
About my presentation Agile Methodology agnostic All the products are open source Best of all, it is workable with JBoss Seam Contains working demos
What technologies will be presented? TestNG Groovy EasyMock Hudson Subversion Cobertura DBUnit Selenium
TestNG
What is TestNG? A next generation test framework A framework that makes use of test groupings A framework that doesn't require a test suite. A framework that allows data driven testing and support for parameters. A framework that uses either annotation-based configuration (>= Java 5.0) or java-doc based configuration (< Java 5.0)
Comparison to JUnit TestNG runs JUnit tests so you don't have tear down any previous JUnit tests. TestNG doesn't require Test Suites classes. TestNG can groups tests, and run based on regular expressions. TestNG isn't tightly integrated into Ant.
Groovy
What is Groovy. Groovy is Groovy, yeah baby. Groovy is an optional typed scripting language that runs on the JVM. Extends from Java to provide closures, dynamic lists, builders, overloading, coercions and more. Low learning curve for Java Developers since it based off the Java language. Full Access to Java API, and best of all, you can develop seam entity and action beans using groovy.
Importance of a scripting language in agile development It is your power tool language Great for code generation Great for test data creation Great for generating programming utilities. Great for database cleanup, loader, and manipulation.
Getting Started in your Agile Project To start off you need: Version control system Issue tracking software  Continuous Integration software
Version Control System
What is Version Control? Also known as VCS (Version Control System) or SCM (Source Code Management) It is repository management of multiple versions of your source code. In other words, if you messed something up all this week you can go back and get back the working model of your project. It also can alert of conflicts, which occurs when two developers working on the same file.  It's not magical, it does require proper management,  and constant check-ins in  order to work properly
Open Source List of Common Version Control Systems Subversion (recommended) (Apache/BSD License) CVS (well-known) (GPL) Mercurial (currently runs OpenJDK) (GPL) For a list of open-source and commercial version control software, visit: http://en.wikipedia.org/wiki/Comparison_of_revision_control_software
Subversion Modern SCM that was designed to overcome CVS shortcomings. Apache HTTP Server with WebDAV protocol which allows file management over the web. Simple syntactical commands (e.g. branching and tagging is merely copying directories) All transactions are atomic (do it all, or fail), so there is no corruption.
Setting up subversion Binaries or referral to binaries for Windows, Solaris, Open/FreeBSD can be found at:  http://subversion.tigris.org/project_packages.html Debian GNU/Linux & Ubuntu, just run the command: apt-get install subversion Fedora Core 3 or later, just run the command:  yum install subversion Windows users can also install using Cygwin
Setting Up Subversion Continued Check if installed right by running the command:  svn --version  Then to create a repository  Create the directory for the repository using mkdir Turn it into a subversion repository using svnadmin create Windows: svnadmin create  C:\my_project_repos Linux/Unix: svnadmin create /home/danno/my_project_repos
Setting Up Subversion Continued Importing from filesystem svn import -m “importing from filesystem”  /home/danno/my_project_to_be_imported Importing from CVS Requires planning before the ultimate conversion Don't do it when intoxicated, or listening to rave music When ready you can run cvs2svn command with your options. See: http://cvs2svn.tigris.org/cvs2svn.html#prep
Subversion Basic Commands svn add  svn blame or svn praise svn cat svn checkout or svn co svn cleanup svn commit or svn ci svn copy or svn cp svn delete or svn del or svn rm or svn remove
Subversion Basic Commands Continued svn diff or svn di svn export svn import svn info svn list or svn ls svn log svn merge svn mkdir
Subversion Basic Commands Continued svn move or svn mv svn status svn resolved svn revert  svn switch or svn sw  (great power comes with great responsibility) svn update or svn up
Quick reference to your trunk, tagging, and branching.
Creating a trunk The trunk directory is where the core development takes place.  The trunk is always changing and is not where “code freezes” take place. To create the trunk, just create a directory at the root of your repository using: svn mkdir trunk.
Creating a Release Branch A release branch is created when the trunk development is ready for a release.  To create a branches directory: svn mkdir -m “create branch dir” <repos_root>/branches Then create the branch from the trunk: svn cp -m “create release branch” <repos_root>/trunk <repos_root>/branches/RB-<version_number> RB is a convention acronym for release branch
Switching Now that you have a branch and trunk you can switch between them both Caution needs to be used.  Commit before switching! svn switch, switches repository directory of your choosing For example svn switch <repos_root>/branches/RB-<version_number> switches to the branch svn switch <repos_root>/trunk switches back to the trunk
Tagging a release A tag directory is like a branch directory, but developers DO NOT make changes to it. It is an artifact for archival purposes. Make sure you have a tags directory. svn mkdir -m “create tags dir” <repos_root>/tags Create the tagged artifact by copying the branch directory svn cp -m “Tag release” <repos_root>/branches/RB-<version_number> <repos_root>/tags/REL-<version_number>
More to learn and not a lot of time  Pragmatic Version Control Using Subversion What I didn't cover More tagging strategies Repository setup Binary handling  Externals and more.
Continuous Integration
Definition of continuous integration A practice in agile development of continually committing your code to a revision control system, and running tests as a community in order to receive instant feedback. Benefits include: Early detection of integration problems and broken code. Shorter feedback cycles Stakeholder continually has a working project. Constant reporting on health of the project.
List of Continuous Integration Software Hudson  CruiseControl Continuum for Maven
Hudson Hudson works with different build files like Ant and Maven Web based, and not XML based Nice Interface Easy installation https://hudson.dev.java.net/
Setting up Hudson Download the .war file Create a directory where the builds will go, and map the environment variable HUDSON_HOME to it. Throw it into your favorite servlet container or application server.  I don't know I heard JBoss makes one.
Plugins for Hudson  A wide variety of plug-ins are available for hudson. http://hudson.gotdns.com/wiki/display/HUDSON/Plugins
Bug Tracking Software Use your favorite Waiting for the JBoss Seam based bug tracking software ;)
Finally.... We are ready to actually work on the project.
Some behind the scenes took place Installed JBoss Seam on my machine I used Seam-gen to create my project, my project is called jboss_world_2008 I created the app as an “in-process” project because:  I was too lazy to do an entire web project for a 90 minute presentation. Accurately reflects a project in development. ;) A tour of what JBoss Seam created, and also a tour of Subversion, TestNG, Hudson, and  Seam together as one.
Unit-testing
Definition of unit-testing From Wikipedia: Unit testing is a procedure used to validate that individual units of source code are working properly.  In Object Oriented Programming the smallest unit is the method Unit-tests should be done at time of method creation In fact, it's even better to develop your unit-tests before method creation. This is known as Test Driven Development
Good Advice on Testing Try to make the test the same package as the class being tested.
Some other good advice in developing in Seam There will be many times where you can use the Seam Framework instead of developing your classes and tests.
Entity Bean Testing Java Entity Bean Testing Demo Groovy Entity Bean Testing Demo
Session Beans or &quot;Action Beans&quot;
Dependency Injection/Inversion of Control From Wikipedia: Dependency injection (DI) refers to the process of supplying an external dependency to a software component and is a specific form of inversion of control where the concern being inverted is the process of obtaining the needed dependency. Seam makes heavy use of DI with annotations to bring services that are required. Demo
Interface Oriented Design Strive to make every service or action defined by an interface.  Allows for better testability. Allows you to create Mocks in it's place for unit testing It loosely decouples your application. Makes for a better Dependency Injected solution. EJB3 Stateful and Stateless Session Beans have Local and Remote Interfaces that describe the service.
Unit-testing action beans
Dummies, Fakes, Mocks, & Stubs According to Martin Fowler: Dummy objects are passed around but never actually used. Usually they are just used to fill parameter lists. Fake objects actually have working implementations, but usually take some shortcut which makes them not suitable for production (an in memory database is a good example).
Dummies, Fakes, Mocks, & Stubs Stubs provide canned answers to calls made during the test, usually not responding at all to anything outside what's programmed in for the test. Stubs may also record information about calls, such as an email gateway stub that remembers the messages it 'sent', or maybe only how many messages it 'sent'. Mocks are objects pre-programmed with expectations which form a specification of the calls they are expected to receive.
EasyMock EasyMock allows you to mock out a service required for your service, and you as the programmer can act out the behavior of that mocked service. Downloadable at easymock.org The latest version 2.3 makes great use of generics and makes it's use simpler than previous versions. Easy to install; Download easymock and the easymockextension from the website, and include it your lib directory of your seam app.
EasyMock continued The whole idea behind easymock is “simplish”. Create the mock object Act out the behavior of the mock replay() the mock object run the method you are testing verify() that everything ran as you planned Honestly, it will take a while to get your head wrapped around it.  Once you see it and realize it's use, it will be invaluable. Demo
You talked about Groovy, so what about Groovy? Groovy can use anything built in Java, therefore in order to create mocks in Groovy testing use EasyMock. Groovy has a built in EasyMock mechanism inspired by the earlier releases of EasyMock.  The learning curve is a bit harder, but it is certainly a viable solution. I recommend sticking to EasyMock. Groovy really shines when it comes to creating stubs, using something called Map Coercion. Demo
Classextensions of easymock. EasyMock by itself only works with interfaces. EasyMock extension creates a mock out of abstract classes. Once you have both in your classpath, you can use static imports in your test class to use the same API with knowing that you are using different libraries.
Integration-testing
Definition of integration-testing Actually Microsoft had the better definition: Integration testing is a logical extension of unit testing. In its simplest form, two units that have already been tested are combined into a component and the interface between them is tested. In other words, we mocked our entityManager, now let's try to see if a real entityManager with a database works.  Integration testing doesn't exclusively mean databases, it just means two components.
When to integration test? After the unit test, and of course after the other components you are integrating with is ready and available. If your component relies on three other components, and you only have one component to integrate with, you can always use mocks for the not yet available components.
Seam based testing One word AWESOME You are able to use JSF expression language within the test to bind components and run the test Uses JBoss Embeddable as a “mini-me” of an actual JBoss Server In the case of database-based integration testing, you can use DBUnit with Seam to load fake data into the memory database in order to do the tests. Demo
Seam based testing caveats and warnings. A little rough to set up Classpath order is everything, and the embeddable server is very specific (a.k.a whiny) on where it's classes come from. Seam-gen's build.xml is the best reference on how to set that up, or just use seam-gen. Documentation didn't specify where to put dbunit files (grrr). I placed a folder in the resources folder and made reference to it from without a beginning slash.
Seam based testing caveats and warnings. Documentation says that integration testing only works on Java 5.0 and not Java 6.0. I was able to make it work for Java 6.0 by adding:  <sysproperty key=&quot;sun.lang.ClassLoader.allowArraySyntax&quot; value=&quot;true&quot;/> to the testng task. I am not a fan of extending SeamTest or DBUnitSeamTest in order to do my testing, and prefer composition over inheritance. (see Josh Bloch's Effective Java)
JBoss Seam &quot;Mocking&quot; Precedence JBoss Seam gives the ability to mock or stub any component during integration test by giving the users the ability to use the Install annotation. @Install(precedence=MOCK) The Install annotation ensures that the component annotated will be installed for testing, but not installed during production. Great idea in case that you may want to substitute one component that is not available or  that is costly to run (i.e. for pay web services). Demo
JSF Based integration testing. Seam allows you to emulate JSF Request Cycles (see next slide). Uses anonymous inner class SeamTest.FacesRequest Especially useful if you have a complicated JSF page that you wish to mimic.  Demo
Review of JSF Request Lifecycles
Acceptance-testing
Definition of acceptance-testing According to Wikipedia: In engineering and its various subdisciplines, acceptance testing is black-box testing performed on a system (e.g. software, lots of manufactured mechanical parts, or batches of chemical products) prior to its delivery. In some engineering subdisciplines, it is known as functional testing, black-box testing, release acceptance, QA testing, application testing, confidence testing, final testing, validation testing, usability testing, or factory acceptance testing.
Definition of acceptance-testing My definition: Take your prototype out for a spin!
When to acceptance test? The day before deployment, not really, after unit testing phase, and the integration testing phase, and any other types of testing that you wish to do before including security testing, performance testing, etc.
Selenium Developed by a team of programmers and testers at Thoughtworks and is housed under OpenQA A javascript based test tool Runs directly in the browser Creates a test script in your favorite language Has an IDE that can run under Firefox in order to run your test.
Before getting started Make sure that you include ids in all your components, selenium uses ids extensively.  This also includes <h:form>
Setting up Selenium IDE for Firefox Retrieve the IDE at  http://www.openqa.org/selenium-ide/  using Firefox.  The Firefox extension will load on Firefox and would want to restart. Currently there are no Selenium IDE's for Safari or IE. Create tests on your webapp.  Demo.
Selenium Core Selenium Core allows you to create tests in a table and run those tests from your website. To set it up, download Selenium Core from  http://www.openqa.org/selenium-core/ Expand the file, and place the core folder in the view folder of your seam application. Create Tests and TestSuite Visit http://<webservername>:<port>/core/TestRunner.html on your web application. Demo
Setting up Selenium Server RC Go to  http://selenium-rc.openqa.org/index.html  and download seleniumrc Expand the file In the selenium-remote control folder, go to selenium server folder and run selenium-server.jar Then go to selenium-java-client-driver and get the selenium client jar and place it your lib directory Create a script from your Selenium IDE, and make a test case out  the test. Demo.
Headless Linux/Unix server? For Linux, use xvfb, which (IN THEORY) creates virtual frame buffer to emulate a frame terminal.  For more information, visit, http://linux.about.com/cs/linux101/g/xvfb.htm
Code Coverage
What is Code Coverage? Utility that measures and calculates the percentage of source code actually covered by tests. Code Coverage can improve the quality and predictability of your software. Code Coverage only measure the coverage, but not quality of your code or your tests.  That is still up to you. Code Coverage usually instruments your class file so that it can report the actual coverage in your project.
Open Source Code Coverage Cobertura Emma
Cobertura Spanish and Portuguese word for 'Coverage' . Can run at the command line or as an ant task. Plugins available for Maven. Also reports the McCabe cyclomatic code complexity of each class. The McCabe complexity shows how complicated you method or code is. Strive for a lower McCabe complexity in all your methods.
Setting up Cobertura Download at  http://cobertura.sourceforge.net/download.html Copy the cobertura.jar, and all the jars in the lib directory into your jboss seam lib folder. Apply necessary changes to your build.xml file  Demo
Using Cobertura Once your Cobertura is complete in your build.xml file, run some of your tests. Depending on your folder naming, an HTML report, or an XML report or both should be available for your analysis. There is a Cobertura plugin available on Hudson so that code coverage Demo
Emma Can run at the command line, as an ant task, or a makefile.  Two kinds of class instrumentation, offline, and on the fly.  Plain text, HTML, or XML reporting Can instrument jar files, not just .class files More information is located at http://emma.sourceforge.net/
Other tools worth mentioning XMLUnit (xmlunit.sourceforge.net) – helps you assert that two XMLs are equal. FitNess (http://fitnesse.org/) Dumbster (http://quintanasoft.com/dumbster/)
For more information JBoss Seam  http://www.jboss.com/products/seam JBoss Seam Forums  http://www.jboss.com/?module=bb&op=viewforum&f=231 JBoss Seam Wiki  http://www.jboss.com/wiki/Wiki.jsp?page=JBossSeam Pragmatic Programmer http://www.pragprog.com/ Groovy http://groovy.codehaus.org/
Thank You

Jbossworld Presentation

  • 1.
    Agile Development UsingJboss Seam Daniel Hinojosa Evolutionnext Programmer/Developer/Instructor 02/15/08
  • 2.
    What is AgileDevelopment? According to Wikipedia: It is a conceptual framework for software engineering that promotes development iterations throughout the life-cycle of the project. Each iteration includes development, testing, documentation, and a functioning working product after each iteration. Various Agile Methodologies out there Scrum, Crystal Clear, XP (Extreme Programming), Feature Driven Development, and more.
  • 3.
    About my presentationAgile Methodology agnostic All the products are open source Best of all, it is workable with JBoss Seam Contains working demos
  • 4.
    What technologies willbe presented? TestNG Groovy EasyMock Hudson Subversion Cobertura DBUnit Selenium
  • 5.
  • 6.
    What is TestNG?A next generation test framework A framework that makes use of test groupings A framework that doesn't require a test suite. A framework that allows data driven testing and support for parameters. A framework that uses either annotation-based configuration (>= Java 5.0) or java-doc based configuration (< Java 5.0)
  • 7.
    Comparison to JUnitTestNG runs JUnit tests so you don't have tear down any previous JUnit tests. TestNG doesn't require Test Suites classes. TestNG can groups tests, and run based on regular expressions. TestNG isn't tightly integrated into Ant.
  • 8.
  • 9.
    What is Groovy.Groovy is Groovy, yeah baby. Groovy is an optional typed scripting language that runs on the JVM. Extends from Java to provide closures, dynamic lists, builders, overloading, coercions and more. Low learning curve for Java Developers since it based off the Java language. Full Access to Java API, and best of all, you can develop seam entity and action beans using groovy.
  • 10.
    Importance of ascripting language in agile development It is your power tool language Great for code generation Great for test data creation Great for generating programming utilities. Great for database cleanup, loader, and manipulation.
  • 11.
    Getting Started inyour Agile Project To start off you need: Version control system Issue tracking software Continuous Integration software
  • 12.
  • 13.
    What is VersionControl? Also known as VCS (Version Control System) or SCM (Source Code Management) It is repository management of multiple versions of your source code. In other words, if you messed something up all this week you can go back and get back the working model of your project. It also can alert of conflicts, which occurs when two developers working on the same file. It's not magical, it does require proper management, and constant check-ins in order to work properly
  • 14.
    Open Source Listof Common Version Control Systems Subversion (recommended) (Apache/BSD License) CVS (well-known) (GPL) Mercurial (currently runs OpenJDK) (GPL) For a list of open-source and commercial version control software, visit: http://en.wikipedia.org/wiki/Comparison_of_revision_control_software
  • 15.
    Subversion Modern SCMthat was designed to overcome CVS shortcomings. Apache HTTP Server with WebDAV protocol which allows file management over the web. Simple syntactical commands (e.g. branching and tagging is merely copying directories) All transactions are atomic (do it all, or fail), so there is no corruption.
  • 16.
    Setting up subversionBinaries or referral to binaries for Windows, Solaris, Open/FreeBSD can be found at: http://subversion.tigris.org/project_packages.html Debian GNU/Linux & Ubuntu, just run the command: apt-get install subversion Fedora Core 3 or later, just run the command: yum install subversion Windows users can also install using Cygwin
  • 17.
    Setting Up SubversionContinued Check if installed right by running the command: svn --version Then to create a repository Create the directory for the repository using mkdir Turn it into a subversion repository using svnadmin create Windows: svnadmin create C:\my_project_repos Linux/Unix: svnadmin create /home/danno/my_project_repos
  • 18.
    Setting Up SubversionContinued Importing from filesystem svn import -m “importing from filesystem” /home/danno/my_project_to_be_imported Importing from CVS Requires planning before the ultimate conversion Don't do it when intoxicated, or listening to rave music When ready you can run cvs2svn command with your options. See: http://cvs2svn.tigris.org/cvs2svn.html#prep
  • 19.
    Subversion Basic Commandssvn add svn blame or svn praise svn cat svn checkout or svn co svn cleanup svn commit or svn ci svn copy or svn cp svn delete or svn del or svn rm or svn remove
  • 20.
    Subversion Basic CommandsContinued svn diff or svn di svn export svn import svn info svn list or svn ls svn log svn merge svn mkdir
  • 21.
    Subversion Basic CommandsContinued svn move or svn mv svn status svn resolved svn revert svn switch or svn sw (great power comes with great responsibility) svn update or svn up
  • 22.
    Quick reference toyour trunk, tagging, and branching.
  • 23.
    Creating a trunkThe trunk directory is where the core development takes place. The trunk is always changing and is not where “code freezes” take place. To create the trunk, just create a directory at the root of your repository using: svn mkdir trunk.
  • 24.
    Creating a ReleaseBranch A release branch is created when the trunk development is ready for a release. To create a branches directory: svn mkdir -m “create branch dir” <repos_root>/branches Then create the branch from the trunk: svn cp -m “create release branch” <repos_root>/trunk <repos_root>/branches/RB-<version_number> RB is a convention acronym for release branch
  • 25.
    Switching Now thatyou have a branch and trunk you can switch between them both Caution needs to be used. Commit before switching! svn switch, switches repository directory of your choosing For example svn switch <repos_root>/branches/RB-<version_number> switches to the branch svn switch <repos_root>/trunk switches back to the trunk
  • 26.
    Tagging a releaseA tag directory is like a branch directory, but developers DO NOT make changes to it. It is an artifact for archival purposes. Make sure you have a tags directory. svn mkdir -m “create tags dir” <repos_root>/tags Create the tagged artifact by copying the branch directory svn cp -m “Tag release” <repos_root>/branches/RB-<version_number> <repos_root>/tags/REL-<version_number>
  • 27.
    More to learnand not a lot of time Pragmatic Version Control Using Subversion What I didn't cover More tagging strategies Repository setup Binary handling Externals and more.
  • 28.
  • 29.
    Definition of continuousintegration A practice in agile development of continually committing your code to a revision control system, and running tests as a community in order to receive instant feedback. Benefits include: Early detection of integration problems and broken code. Shorter feedback cycles Stakeholder continually has a working project. Constant reporting on health of the project.
  • 30.
    List of ContinuousIntegration Software Hudson CruiseControl Continuum for Maven
  • 31.
    Hudson Hudson workswith different build files like Ant and Maven Web based, and not XML based Nice Interface Easy installation https://hudson.dev.java.net/
  • 32.
    Setting up HudsonDownload the .war file Create a directory where the builds will go, and map the environment variable HUDSON_HOME to it. Throw it into your favorite servlet container or application server. I don't know I heard JBoss makes one.
  • 33.
    Plugins for Hudson A wide variety of plug-ins are available for hudson. http://hudson.gotdns.com/wiki/display/HUDSON/Plugins
  • 34.
    Bug Tracking SoftwareUse your favorite Waiting for the JBoss Seam based bug tracking software ;)
  • 35.
    Finally.... We areready to actually work on the project.
  • 36.
    Some behind thescenes took place Installed JBoss Seam on my machine I used Seam-gen to create my project, my project is called jboss_world_2008 I created the app as an “in-process” project because: I was too lazy to do an entire web project for a 90 minute presentation. Accurately reflects a project in development. ;) A tour of what JBoss Seam created, and also a tour of Subversion, TestNG, Hudson, and Seam together as one.
  • 37.
  • 38.
    Definition of unit-testingFrom Wikipedia: Unit testing is a procedure used to validate that individual units of source code are working properly. In Object Oriented Programming the smallest unit is the method Unit-tests should be done at time of method creation In fact, it's even better to develop your unit-tests before method creation. This is known as Test Driven Development
  • 39.
    Good Advice onTesting Try to make the test the same package as the class being tested.
  • 40.
    Some other goodadvice in developing in Seam There will be many times where you can use the Seam Framework instead of developing your classes and tests.
  • 41.
    Entity Bean TestingJava Entity Bean Testing Demo Groovy Entity Bean Testing Demo
  • 42.
    Session Beans or&quot;Action Beans&quot;
  • 43.
    Dependency Injection/Inversion ofControl From Wikipedia: Dependency injection (DI) refers to the process of supplying an external dependency to a software component and is a specific form of inversion of control where the concern being inverted is the process of obtaining the needed dependency. Seam makes heavy use of DI with annotations to bring services that are required. Demo
  • 44.
    Interface Oriented DesignStrive to make every service or action defined by an interface. Allows for better testability. Allows you to create Mocks in it's place for unit testing It loosely decouples your application. Makes for a better Dependency Injected solution. EJB3 Stateful and Stateless Session Beans have Local and Remote Interfaces that describe the service.
  • 45.
  • 46.
    Dummies, Fakes, Mocks,& Stubs According to Martin Fowler: Dummy objects are passed around but never actually used. Usually they are just used to fill parameter lists. Fake objects actually have working implementations, but usually take some shortcut which makes them not suitable for production (an in memory database is a good example).
  • 47.
    Dummies, Fakes, Mocks,& Stubs Stubs provide canned answers to calls made during the test, usually not responding at all to anything outside what's programmed in for the test. Stubs may also record information about calls, such as an email gateway stub that remembers the messages it 'sent', or maybe only how many messages it 'sent'. Mocks are objects pre-programmed with expectations which form a specification of the calls they are expected to receive.
  • 48.
    EasyMock EasyMock allowsyou to mock out a service required for your service, and you as the programmer can act out the behavior of that mocked service. Downloadable at easymock.org The latest version 2.3 makes great use of generics and makes it's use simpler than previous versions. Easy to install; Download easymock and the easymockextension from the website, and include it your lib directory of your seam app.
  • 49.
    EasyMock continued Thewhole idea behind easymock is “simplish”. Create the mock object Act out the behavior of the mock replay() the mock object run the method you are testing verify() that everything ran as you planned Honestly, it will take a while to get your head wrapped around it. Once you see it and realize it's use, it will be invaluable. Demo
  • 50.
    You talked aboutGroovy, so what about Groovy? Groovy can use anything built in Java, therefore in order to create mocks in Groovy testing use EasyMock. Groovy has a built in EasyMock mechanism inspired by the earlier releases of EasyMock. The learning curve is a bit harder, but it is certainly a viable solution. I recommend sticking to EasyMock. Groovy really shines when it comes to creating stubs, using something called Map Coercion. Demo
  • 51.
    Classextensions of easymock.EasyMock by itself only works with interfaces. EasyMock extension creates a mock out of abstract classes. Once you have both in your classpath, you can use static imports in your test class to use the same API with knowing that you are using different libraries.
  • 52.
  • 53.
    Definition of integration-testingActually Microsoft had the better definition: Integration testing is a logical extension of unit testing. In its simplest form, two units that have already been tested are combined into a component and the interface between them is tested. In other words, we mocked our entityManager, now let's try to see if a real entityManager with a database works. Integration testing doesn't exclusively mean databases, it just means two components.
  • 54.
    When to integrationtest? After the unit test, and of course after the other components you are integrating with is ready and available. If your component relies on three other components, and you only have one component to integrate with, you can always use mocks for the not yet available components.
  • 55.
    Seam based testingOne word AWESOME You are able to use JSF expression language within the test to bind components and run the test Uses JBoss Embeddable as a “mini-me” of an actual JBoss Server In the case of database-based integration testing, you can use DBUnit with Seam to load fake data into the memory database in order to do the tests. Demo
  • 56.
    Seam based testingcaveats and warnings. A little rough to set up Classpath order is everything, and the embeddable server is very specific (a.k.a whiny) on where it's classes come from. Seam-gen's build.xml is the best reference on how to set that up, or just use seam-gen. Documentation didn't specify where to put dbunit files (grrr). I placed a folder in the resources folder and made reference to it from without a beginning slash.
  • 57.
    Seam based testingcaveats and warnings. Documentation says that integration testing only works on Java 5.0 and not Java 6.0. I was able to make it work for Java 6.0 by adding: <sysproperty key=&quot;sun.lang.ClassLoader.allowArraySyntax&quot; value=&quot;true&quot;/> to the testng task. I am not a fan of extending SeamTest or DBUnitSeamTest in order to do my testing, and prefer composition over inheritance. (see Josh Bloch's Effective Java)
  • 58.
    JBoss Seam &quot;Mocking&quot;Precedence JBoss Seam gives the ability to mock or stub any component during integration test by giving the users the ability to use the Install annotation. @Install(precedence=MOCK) The Install annotation ensures that the component annotated will be installed for testing, but not installed during production. Great idea in case that you may want to substitute one component that is not available or that is costly to run (i.e. for pay web services). Demo
  • 59.
    JSF Based integrationtesting. Seam allows you to emulate JSF Request Cycles (see next slide). Uses anonymous inner class SeamTest.FacesRequest Especially useful if you have a complicated JSF page that you wish to mimic. Demo
  • 60.
    Review of JSFRequest Lifecycles
  • 61.
  • 62.
    Definition of acceptance-testingAccording to Wikipedia: In engineering and its various subdisciplines, acceptance testing is black-box testing performed on a system (e.g. software, lots of manufactured mechanical parts, or batches of chemical products) prior to its delivery. In some engineering subdisciplines, it is known as functional testing, black-box testing, release acceptance, QA testing, application testing, confidence testing, final testing, validation testing, usability testing, or factory acceptance testing.
  • 63.
    Definition of acceptance-testingMy definition: Take your prototype out for a spin!
  • 64.
    When to acceptancetest? The day before deployment, not really, after unit testing phase, and the integration testing phase, and any other types of testing that you wish to do before including security testing, performance testing, etc.
  • 65.
    Selenium Developed bya team of programmers and testers at Thoughtworks and is housed under OpenQA A javascript based test tool Runs directly in the browser Creates a test script in your favorite language Has an IDE that can run under Firefox in order to run your test.
  • 66.
    Before getting startedMake sure that you include ids in all your components, selenium uses ids extensively. This also includes <h:form>
  • 67.
    Setting up SeleniumIDE for Firefox Retrieve the IDE at http://www.openqa.org/selenium-ide/ using Firefox. The Firefox extension will load on Firefox and would want to restart. Currently there are no Selenium IDE's for Safari or IE. Create tests on your webapp. Demo.
  • 68.
    Selenium Core SeleniumCore allows you to create tests in a table and run those tests from your website. To set it up, download Selenium Core from http://www.openqa.org/selenium-core/ Expand the file, and place the core folder in the view folder of your seam application. Create Tests and TestSuite Visit http://<webservername>:<port>/core/TestRunner.html on your web application. Demo
  • 69.
    Setting up SeleniumServer RC Go to http://selenium-rc.openqa.org/index.html and download seleniumrc Expand the file In the selenium-remote control folder, go to selenium server folder and run selenium-server.jar Then go to selenium-java-client-driver and get the selenium client jar and place it your lib directory Create a script from your Selenium IDE, and make a test case out the test. Demo.
  • 70.
    Headless Linux/Unix server?For Linux, use xvfb, which (IN THEORY) creates virtual frame buffer to emulate a frame terminal. For more information, visit, http://linux.about.com/cs/linux101/g/xvfb.htm
  • 71.
  • 72.
    What is CodeCoverage? Utility that measures and calculates the percentage of source code actually covered by tests. Code Coverage can improve the quality and predictability of your software. Code Coverage only measure the coverage, but not quality of your code or your tests. That is still up to you. Code Coverage usually instruments your class file so that it can report the actual coverage in your project.
  • 73.
    Open Source CodeCoverage Cobertura Emma
  • 74.
    Cobertura Spanish andPortuguese word for 'Coverage' . Can run at the command line or as an ant task. Plugins available for Maven. Also reports the McCabe cyclomatic code complexity of each class. The McCabe complexity shows how complicated you method or code is. Strive for a lower McCabe complexity in all your methods.
  • 75.
    Setting up CoberturaDownload at http://cobertura.sourceforge.net/download.html Copy the cobertura.jar, and all the jars in the lib directory into your jboss seam lib folder. Apply necessary changes to your build.xml file Demo
  • 76.
    Using Cobertura Onceyour Cobertura is complete in your build.xml file, run some of your tests. Depending on your folder naming, an HTML report, or an XML report or both should be available for your analysis. There is a Cobertura plugin available on Hudson so that code coverage Demo
  • 77.
    Emma Can runat the command line, as an ant task, or a makefile. Two kinds of class instrumentation, offline, and on the fly. Plain text, HTML, or XML reporting Can instrument jar files, not just .class files More information is located at http://emma.sourceforge.net/
  • 78.
    Other tools worthmentioning XMLUnit (xmlunit.sourceforge.net) – helps you assert that two XMLs are equal. FitNess (http://fitnesse.org/) Dumbster (http://quintanasoft.com/dumbster/)
  • 79.
    For more informationJBoss Seam http://www.jboss.com/products/seam JBoss Seam Forums http://www.jboss.com/?module=bb&op=viewforum&f=231 JBoss Seam Wiki http://www.jboss.com/wiki/Wiki.jsp?page=JBossSeam Pragmatic Programmer http://www.pragprog.com/ Groovy http://groovy.codehaus.org/
  • 80.