Archive

Archive for the ‘Testing’ Category

Automation testing with Flex Monkey (Reloaded) and Maven

August 8, 2011 Leave a comment

Lately there are lot of questions on the flex monkey forum running the functional testing with maven. However there are more questions related to converting the ant script into maven stuff.

Thought of posting the steps that we use to run the automated testing with maven.

Create a maven profile to run the automation tests only when you need that. This will obviously save some time when you dont need to run each time, since you are not running it part of the maven build lifecycle.  More information on build profiles can be found at this link

Maven-antrun-plugin provides the ability to run ant tasks from maven.

 <profile>
<id>automate</id>
<build>
<plugins>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<phase>test</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>

<tasks unless=”maven.test.skip”>
<delete file=”${basedir}/automation/build.properties”/>
<copy file=”${basedir}/automation/build.local.properties”
tofile=”${basedir}/automation/build.properties”/>
<ant antfile=”${basedir}/automation/build.xml”>
</ant>
</tasks>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.apache.ant</groupId>
<artifactId>ant</artifactId>
<version>1.7.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>ant</groupId>
<artifactId>ant-optional</artifactId>
<version>1.5.3-1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.ant</groupId>
<artifactId>ant-apache-xalan2</artifactId>
<version>1.8.2</version>
</dependency>
</dependencies>
</plugin>
</plugins>

</build>
</profile>

If you see the above code, it runs the antfile “build.xml” which is in automation folder. The build.properties are the files which is needed for my application to set the channel end points ( channel Endpoint url are different for  development, scrum, qa and also for prod). The configurations can be used to override the properties file used by ant to change the channel configuration.

There are many ways to dymanically change the channel configuration run-time by loading xmls.., changing serverconfig data and also by changing the services-config url as well etc..,

The libraries which are added in dependency section are need to generate the Junitreport tasks.

If you run the build.xml within flex builder, it would run the “junitreport” task without any issue. Since it would use the built-in jar available within flash builder plugins sections. But when running with maven, you need the above dependencies artifacts (ant , ant-optional and ant-apache-xalan2) for the report generation to work.

Here is the core part of the build XML which is used to run the generated flex unit tests (either recorded ones as well by flex monkey)

    <target name=”execute_test” depends=”initTest”>
<echo>${build.dir}/${main}.swf</echo>
<flexunit
url=”file://${build.dir}/${main}.swf”
command=”${monkey.launch.app}”
toDir=”${report.dir}”
haltonfailure=”false”
verbose=”true” />

<echo message=”Flex Monkey reports are generated to ${report.dir}” />

<junitreport todir=”${report.dir}”>
<fileset dir=”${report.dir}” >
<include name=”TEST-*.xml”/>
</fileset>
<report format=”frames”  todir=”${report.dir}/html”/>
</junitreport>
</target>

Curious to know if there is any effective way to run automated testing for your flex apps. Please could you mention that in comments section.

Advertisements
Categories: Flex, Flex monkey, Testing