Download - Ant Unit Your Functional Test
![Page 1: Ant Unit Your Functional Test](https://reader034.vdocument.in/reader034/viewer/2022051400/553892af4a79597a748b47a9/html5/thumbnails/1.jpg)
AntUnit Your Functional Test
Jimmy Zhao
Dec 30, 2008
![Page 2: Ant Unit Your Functional Test](https://reader034.vdocument.in/reader034/viewer/2022051400/553892af4a79597a748b47a9/html5/thumbnails/2.jpg)
![Page 3: Ant Unit Your Functional Test](https://reader034.vdocument.in/reader034/viewer/2022051400/553892af4a79597a748b47a9/html5/thumbnails/3.jpg)
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
![Page 4: Ant Unit Your Functional Test](https://reader034.vdocument.in/reader034/viewer/2022051400/553892af4a79597a748b47a9/html5/thumbnails/4.jpg)
What?• Ant & AntUnit
• For people– Agile developers– People largely involves in testing?– Looking for a solution for build & testing– Loose coupling – Complex application environment
![Page 5: Ant Unit Your Functional Test](https://reader034.vdocument.in/reader034/viewer/2022051400/553892af4a79597a748b47a9/html5/thumbnails/5.jpg)
Agenda
• Why AntUnit?
• How to use & extend it?
• My simple AntUnit extensions
• Examples & Demo
• More thoughts
• Q & A
![Page 6: Ant Unit Your Functional Test](https://reader034.vdocument.in/reader034/viewer/2022051400/553892af4a79597a748b47a9/html5/thumbnails/6.jpg)
Pain of Agile Developers
![Page 7: Ant Unit Your Functional Test](https://reader034.vdocument.in/reader034/viewer/2022051400/553892af4a79597a748b47a9/html5/thumbnails/7.jpg)
http://www.siafu.ca/files/smallANTEL_2.jpg
• test == workload
• test == boring
• test == low value
• test == QA
• test != developer
QualityTest ==
?
![Page 8: Ant Unit Your Functional Test](https://reader034.vdocument.in/reader034/viewer/2022051400/553892af4a79597a748b47a9/html5/thumbnails/8.jpg)
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
![Page 9: Ant Unit Your Functional Test](https://reader034.vdocument.in/reader034/viewer/2022051400/553892af4a79597a748b47a9/html5/thumbnails/9.jpg)
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.
![Page 10: Ant Unit Your Functional Test](https://reader034.vdocument.in/reader034/viewer/2022051400/553892af4a79597a748b47a9/html5/thumbnails/10.jpg)
Why AntUnit?
Most flexible way to assert your functions
Great extendibility
So many tasks ready for use
Perfectly integrate with development environment
Controllable granularity
![Page 11: Ant Unit Your Functional Test](https://reader034.vdocument.in/reader034/viewer/2022051400/553892af4a79597a748b47a9/html5/thumbnails/11.jpg)
Picture from: deviantart.com Paradox__Ant_and_Elephant_by_Darkberry_Fruity.jpg
Call Me “Elephant”
![Page 12: Ant Unit Your Functional Test](https://reader034.vdocument.in/reader034/viewer/2022051400/553892af4a79597a748b47a9/html5/thumbnails/12.jpg)
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
![Page 13: Ant Unit Your Functional Test](https://reader034.vdocument.in/reader034/viewer/2022051400/553892af4a79597a748b47a9/html5/thumbnails/13.jpg)
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
![Page 14: Ant Unit Your Functional Test](https://reader034.vdocument.in/reader034/viewer/2022051400/553892af4a79597a748b47a9/html5/thumbnails/14.jpg)
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
![Page 15: Ant Unit Your Functional Test](https://reader034.vdocument.in/reader034/viewer/2022051400/553892af4a79597a748b47a9/html5/thumbnails/15.jpg)
Before Extend AntUnit• Just like A normal ant tasks
• Something your should know – Condition and Fail– XML Namespace awareness– AntListener– Sequential– Macrodef & Scriptdef
![Page 16: Ant Unit Your Functional Test](https://reader034.vdocument.in/reader034/viewer/2022051400/553892af4a79597a748b47a9/html5/thumbnails/16.jpg)
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>
![Page 17: Ant Unit Your Functional Test](https://reader034.vdocument.in/reader034/viewer/2022051400/553892af4a79597a748b47a9/html5/thumbnails/17.jpg)
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
![Page 18: Ant Unit Your Functional Test](https://reader034.vdocument.in/reader034/viewer/2022051400/553892af4a79597a748b47a9/html5/thumbnails/18.jpg)
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
![Page 19: Ant Unit Your Functional Test](https://reader034.vdocument.in/reader034/viewer/2022051400/553892af4a79597a748b47a9/html5/thumbnails/19.jpg)
CLI Example
<target name="testCLIApp"><exec executable="cmd">
<arg value="/c"/> <arg value="ant.bat"/> <arg value="-p"/>
</exec><au:assert>
</target>
![Page 20: Ant Unit Your Functional Test](https://reader034.vdocument.in/reader034/viewer/2022051400/553892af4a79597a748b47a9/html5/thumbnails/20.jpg)
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>
![Page 21: Ant Unit Your Functional Test](https://reader034.vdocument.in/reader034/viewer/2022051400/553892af4a79597a748b47a9/html5/thumbnails/21.jpg)
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
![Page 22: Ant Unit Your Functional Test](https://reader034.vdocument.in/reader034/viewer/2022051400/553892af4a79597a748b47a9/html5/thumbnails/22.jpg)
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
![Page 23: Ant Unit Your Functional Test](https://reader034.vdocument.in/reader034/viewer/2022051400/553892af4a79597a748b47a9/html5/thumbnails/23.jpg)
Similar Ideas
• Webtest project of Canoo– Selenium readable Ant script
• CruiseControl & Plugins
![Page 24: Ant Unit Your Functional Test](https://reader034.vdocument.in/reader034/viewer/2022051400/553892af4a79597a748b47a9/html5/thumbnails/24.jpg)
Resources
• Webtest of Canoo
• CruiseControl & Plugins
• Selenium & projects in OpenQA
• Abbot @ sourceforge
![Page 25: Ant Unit Your Functional Test](https://reader034.vdocument.in/reader034/viewer/2022051400/553892af4a79597a748b47a9/html5/thumbnails/25.jpg)