ant unit your functional test
DESCRIPTION
Ant & AntUnit For people: Agile developers People largely involves in testing? Looking for a solution for build & testing Loose coupling Complex application environmentTRANSCRIPT
AntUnit Your Functional Test
Jimmy Zhao
Dec 30, 2008
About Me
• From China
• More than 8 years of project experience with Ant
• 6 years of Agile experience• Developed a test
engine just like Ant
What?• Ant & AntUnit
• For people– Agile developers– People largely involves in testing?– Looking for a solution for build & testing– Loose coupling – Complex application environment
Agenda
• Why AntUnit?
• How to use & extend it?
• My simple AntUnit extensions
• Examples & Demo
• More thoughts
• Q & A
Pain of Agile Developers
http://www.siafu.ca/files/smallANTEL_2.jpg
• test == workload
• test == boring
• test == low value
• test == QA
• test != developer
QualityTest ==
?
A Silver Bullet For Testing
• Ant – Cover almost every corners of
development– Numerous Ant extensions ready
• AntUnit – just released 1.1 – Test Ant Task – Everything is possible
Official Definition
AntUnit provides Ant tasks for testing Ant task, it can also be used to drive functional and integration tests of arbitrary applications with Ant.
Why AntUnit?
Most flexible way to assert your functions
Great extendibility
So many tasks ready for use
Perfectly integrate with development environment
Controllable granularity
Picture from: deviantart.com Paradox__Ant_and_Elephant_by_Darkberry_Fruity.jpg
Call Me “Elephant”
Ant task too, but we call it assertion here
The Simplest Continuous Integration & Test Solution
Build &
Deploy
Integration Test
System Test
AntUnit
Test Repor
t
Notification
Check Style
All of them are Ant Tasks
Everything Ant
Emma
Two Ways of Using AntUnit
• A: Ant as a drive– Define your test scenario by – Integrate them in Ant
• B: Ant as script engine– Define your test scenario in Ant script– Use Ant xml files to manage your cases
• Don’t forget to assert via AntUnit– White-box testing
Why Extend AntUnit?
• Assert a function is complicated – Business logic
• i.e. web flow with session
– Corner cases of testing• i.e. https authentication
• Combine/reuse existing assertions– Sequential multiple assertions– And/or/xor assertion result– Extend existing tasks
Before Extend AntUnit• Just like A normal ant tasks
• Something your should know – Condition and Fail– XML Namespace awareness– AntListener– Sequential– Macrodef & Scriptdef
Example 1<project name="echo-test" basedir="." default="all" xmlns:au="antlib:org.apache.ant.antunit"> <macrodef name="assertFalse" backtrace="false"> <attribute name="message" default="Assertion failed"/> <element name="assertion" implicit="true"/> <sequential> <au:assertTrue message="@{message}"> <not> <assertion/> </not> </au:assertTrue> </sequential> </macrodef><target></project>
Examples• Command Line application
– Normal Ant tasks + AntUnit• Sshexec/Exec/telnet + assertions
• Web UI application– JUnit extension tasks + AntUnit
• A: HttpUnit/Selenium + assertions• B: AntUnit + assertions based on Selenium
• GUI application– Junit extension tasks + AntUnit
• Abbot + AntUnit
My AntUnit Extensions
• Extension 1– Better functional test purpose assertions
• StdoutAssertion – LogContains Task• FileAssertion – ResourceContains Task• Log4jAssertion – no in 1.1 yet
• Extension 2– Selenium junit extension based task
• Use all of them together
CLI Example
<target name="testCLIApp"><exec executable="cmd">
<arg value="/c"/> <arg value="ant.bat"/> <arg value="-p"/>
</exec><au:assert>
</target>
Web Application Example<target name="testSeleniumTask"> <selenium> <sequential> <command name="open">/</command> <command name="click">btnG</command> <command name="waitForPageToLoad">5000</command> <command
name="click">//div[@id='res']/div[1]/ol/li[1]/h3/a/em</command> <command name="waitForPageToLoad">5000</command> </sequential> </selenium> <au:assertTrue> <command name="isTextPresent">AntUnit 1.1</command> </au:assertTrue> </target>
More Test Purposed Extensions
• Listener as task– For monitoring the testing progress
• Thread-liked/Recursive/Timing task– Embedded runtime & dynamic task
needed, i.e. logging
• Assertion Combination– And/Or/Xor for assertion results
Problems/Found Issues• Setup/TearDown for each test
– It’s good but sometimes also a problem• especially in a functional test environment• Should be configurable
• Not really good at case management– Case dependency is an issue– XML file + Target dependency– Too flexible is also a problem
• Test pattern needed
Similar Ideas
• Webtest project of Canoo– Selenium readable Ant script
• CruiseControl & Plugins
Resources
• Webtest of Canoo
• CruiseControl & Plugins
• Selenium & projects in OpenQA
• Abbot @ sourceforge