Ant Unit Your Functional Test

25
AntUnit Your Functional Test Jimmy Zhao Dec 30, 2008

description

Ant & AntUnit For people: Agile developers People largely involves in testing? Looking for a solution for build & testing Loose coupling Complex application environment

Transcript of Ant Unit Your Functional Test

Page 1: Ant Unit Your Functional Test

AntUnit Your Functional Test

Jimmy Zhao

Dec 30, 2008

Page 2: Ant Unit Your Functional Test
Page 3: Ant Unit Your Functional Test

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

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

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

Pain of Agile Developers

Page 7: Ant Unit Your Functional Test

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

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

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

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 12: Ant Unit Your Functional Test

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

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

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

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

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

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

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

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

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

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

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

Similar Ideas

• Webtest project of Canoo– Selenium readable Ant script

• CruiseControl & Plugins

Page 24: Ant Unit Your Functional Test

Resources

• Webtest of Canoo

• CruiseControl & Plugins

• Selenium & projects in OpenQA

• Abbot @ sourceforge

Page 25: Ant Unit Your Functional Test