You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by jb...@apache.org on 2010/08/23 21:45:33 UTC
svn commit: r988280 - /commons/sandbox/gsoc/2010/scxml-js/trunk/build.xml
Author: jbeard
Date: Mon Aug 23 19:45:33 2010
New Revision: 988280
URL: http://svn.apache.org/viewvc?rev=988280&view=rev
Log:
Moved selenium test out into a macro to allow better code reuse. Added new task run-all-unit-tests to run unit tests with rhino, selenium tests with ahead-of-time compilation, and selenium tests with just-in-time compilation. Note that selenium tests with just-in-time compilation are currently broken in IE, although manual testing succeeds.
Modified:
commons/sandbox/gsoc/2010/scxml-js/trunk/build.xml
Modified: commons/sandbox/gsoc/2010/scxml-js/trunk/build.xml
URL: http://svn.apache.org/viewvc/commons/sandbox/gsoc/2010/scxml-js/trunk/build.xml?rev=988280&r1=988279&r2=988280&view=diff
==============================================================================
--- commons/sandbox/gsoc/2010/scxml-js/trunk/build.xml (original)
+++ commons/sandbox/gsoc/2010/scxml-js/trunk/build.xml Mon Aug 23 19:45:33 2010
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
-<project name="scxml-js" basedir="." default="generate-javascript">
+<project name="scxml-js" basedir="." default="run-all-unit-tests">
<taskdef resource="net/sf/antcontrib/antcontrib.properties">
<classpath>
<pathelement location="${basedir}/lib/build-java/ant-contrib-0.6.jar" />
@@ -306,6 +306,111 @@
</sequential>
</macrodef>
+
+ <macrodef name="run-unit-tests-with-selenium-macro">
+ <attribute name="unit-tests-html-property-name"/>
+
+ <sequential>
+ <rhinoscript><![CDATA[
+ //TODO: consolidate this code
+ function unitTestWithSelenium(sel,url,timeout){
+ sel.open(url);
+
+ sel.waitForPageToLoad("5000");
+
+ // wait for all the tests to finish
+ sel.waitForCondition("window.dohIsComplete", timeout );
+
+ // get the results
+ var testCount = Number(sel.getEval("window.doh._testCount"));
+ var failCount = Number(sel.getEval("window.doh._failureCount"));
+ var errorCount = Number(sel.getEval("window.doh._errorCount"));
+
+ return {
+ testCount:testCount,
+ failCount:failCount,
+ errorCount:errorCount,
+ testsPassed:(testCount - failCount - errorCount)
+ };
+ }
+
+ print("Running Selenium unit tests...");
+
+ var unitTestResults = [];
+
+ browsers.split(",").forEach(function(browserName){
+
+ print("Running test for " + browserName + "...");
+
+ var browserId = project.getProperty("selenium_" + browserName + "_id");
+
+ var bSel = new Packages.com.thoughtworks.selenium.DefaultSelenium(selenium_host, selenium_port, browserId, selenium_root_url);
+
+ print("bSel",bSel);
+
+ bSel.start();
+
+ //list comprehension to get the cartesian product
+ var configurations = [{forIE:forIE,backend:backend,testPath:testPath}
+ for each (forIE in project.getProperty("for-ie").split(','))
+ for each (backend in backends.split(','))
+ for each (testPath in Array.prototype.slice.call(scxml_tests_xml.list()))];
+
+ //use pattern matching in the parameter
+ configurations.forEach(function({forIE:forIE,backend:backend,testPath:testPath}){
+
+ print("forIE:"+forIE+","+"backend:"+backend+","+"testPath:"+testPath);
+
+ //get path to html test
+ //@{for-ie}-@{backend}-@{test-path}-unit-test-html-location
+ var unitTestHtmlLocationPropertyName=forIE + "-" + backend + "-" + testPath + "-@{unit-tests-html-property-name}";
+ var unitTestHtmlLocation = project.getProperty(unitTestHtmlLocationPropertyName);
+
+ print("unitTestHtmlLocation:"+unitTestHtmlLocation);
+
+ //ensure we are not testing an ie html test
+ //on a non-ie browser
+ if(browserName==ie_browser_name && forIE==is_for_ie ||
+ browserName!=ie_browser_name && forIE==is_not_for_ie){
+
+ var unitTestResult = unitTestWithSelenium(bSel,unitTestHtmlLocation,selenium_timeout);
+
+ print("unitTestResult:" + unitTestResult);
+
+ var unitTestResultObj = {
+ data : unitTestResult,
+ browser : browserName,
+ scxmlTest : testPath,
+ backend : backend
+ };
+
+ unitTestResults.push(unitTestResultObj);
+
+ //report errors and failures that may occur
+ if(unitTestResult.failCount || unitTestResult.errorCount){
+ print("UNIT TEST ERROR");
+ //TODO: add better error handling here that integrates with Ant
+ }
+
+ }
+ });
+
+ bSel.stop();
+ });
+
+ var totalTests = unitTestResults.reduce(function(a,b){return a + b.data.testCount},0);
+ var totalTestsFailed = unitTestResults.reduce(function(a,b){return a + b.data.errorCount},0);
+ var totalTestsErrored = unitTestResults.reduce(function(a,b){return a + b.data.failCount},0);
+ var totalTestsPassed = unitTestResults.reduce(function(a,b){return a + b.data.testsPassed},0);
+
+ print("Test Results:");
+ print("Total Tests: " + totalTests);
+ print("Total Tests Failed: " + totalTestsFailed);
+ print("Total Tests Errored: " + totalTestsErrored);
+ print("Total Tests Passed: " + totalTestsPassed);
+ ]]></rhinoscript>
+ </sequential>
+ </macrodef>
<target name="preprocess-stylesheets" depends="init">
<xslt
@@ -590,209 +695,18 @@
</target>
<target name="run-unit-tests-with-selenium" depends="generate-unit-test-html,generate-javascript">
- <rhinoscript><![CDATA[
- function unitTestWithSelenium(sel,url,timeout){
- sel.open(url);
-
- sel.waitForPageToLoad("5000");
-
- // wait for all the tests to finish
- sel.waitForCondition("window.dohIsComplete", timeout );
-
- // get the results
- var testCount = Number(sel.getEval("window.doh._testCount"));
- var failCount = Number(sel.getEval("window.doh._failureCount"));
- var errorCount = Number(sel.getEval("window.doh._errorCount"));
-
- return {
- testCount:testCount,
- failCount:failCount,
- errorCount:errorCount,
- testsPassed:(testCount - failCount - errorCount)
- };
- }
-
- print("Running Selenium unit tests...");
-
- var unitTestResults = [];
-
- browsers.split(",").forEach(function(browserName){
-
- print("Running test for " + browserName + "...");
-
- var browserId = project.getProperty("selenium_" + browserName + "_id");
-
- var bSel = new Packages.com.thoughtworks.selenium.DefaultSelenium(selenium_host, selenium_port, browserId, selenium_root_url);
-
- print("bSel",bSel);
-
- bSel.start();
-
- //list comprehension to get the cartesian product
- var configurations = [{forIE:forIE,backend:backend,testPath:testPath}
- for each (forIE in project.getProperty("for-ie").split(','))
- for each (backend in backends.split(','))
- for each (testPath in Array.prototype.slice.call(scxml_tests_xml.list()))];
-
- //use pattern matching in the parameter
- configurations.forEach(function({forIE:forIE,backend:backend,testPath:testPath}){
-
- print("forIE:"+forIE+","+"backend:"+backend+","+"testPath:"+testPath);
-
- //get path to html test
- //@{for-ie}-@{backend}-@{test-path}-unit-test-html-location
- var unitTestHtmlLocationPropertyName=forIE + "-" + backend + "-" + testPath + "-unit-test-html-location";
- var unitTestHtmlLocation = project.getProperty(unitTestHtmlLocationPropertyName);
-
- print("unitTestHtmlLocation:"+unitTestHtmlLocation);
-
- //ensure we are not testing an ie html test
- //on a non-ie browser
- if(browserName==ie_browser_name && forIE==is_for_ie ||
- browserName!=ie_browser_name && forIE==is_not_for_ie){
-
- var unitTestResult = unitTestWithSelenium(bSel,unitTestHtmlLocation,selenium_timeout);
-
- print("unitTestResult:" + unitTestResult);
-
- var unitTestResultObj = {
- data : unitTestResult,
- browser : browserName,
- scxmlTest : testPath,
- backend : backend
- };
-
- unitTestResults.push(unitTestResultObj);
-
- //report errors and failures that may occur
- if(unitTestResult.failCount || unitTestResult.errorCount){
- print("UNIT TEST ERROR");
- //TODO: add better error handling here that integrates with Ant
- }
-
- }
- });
-
- bSel.stop();
- });
-
- var totalTests = unitTestResults.reduce(function(a,b){return a + b.data.testCount},0);
- var totalTestsFailed = unitTestResults.reduce(function(a,b){return a + b.data.errorCount},0);
- var totalTestsErrored = unitTestResults.reduce(function(a,b){return a + b.data.failCount},0);
- var totalTestsPassed = unitTestResults.reduce(function(a,b){return a + b.data.testsPassed},0);
-
- print("Test Results:");
- print("Total Tests: " + totalTests);
- print("Total Tests Failed: " + totalTestsFailed);
- print("Total Tests Errored: " + totalTestsErrored);
- print("Total Tests Passed: " + totalTestsPassed);
- ]]></rhinoscript>
+ <run-unit-tests-with-selenium-macro
+ unit-tests-html-property-name="unit-test-html-location"/>
</target>
<target name="run-in-browser-unit-tests-with-selenium" depends="preprocess-stylesheets,generate-in-browser-unit-test-html">
- <rhinoscript><![CDATA[
- //TODO: consolidate this code
- function unitTestWithSelenium(sel,url,timeout){
- sel.open(url);
-
- sel.waitForPageToLoad("5000");
-
- // wait for all the tests to finish
- sel.waitForCondition("window.dohIsComplete", timeout );
-
- // get the results
- var testCount = Number(sel.getEval("window.doh._testCount"));
- var failCount = Number(sel.getEval("window.doh._failureCount"));
- var errorCount = Number(sel.getEval("window.doh._errorCount"));
-
- return {
- testCount:testCount,
- failCount:failCount,
- errorCount:errorCount,
- testsPassed:(testCount - failCount - errorCount)
- };
- }
-
- print("Running Selenium unit tests...");
-
- var unitTestResults = [];
-
- browsers.split(",").forEach(function(browserName){
-
- print("Running test for " + browserName + "...");
-
- var browserId = project.getProperty("selenium_" + browserName + "_id");
-
- var bSel = new Packages.com.thoughtworks.selenium.DefaultSelenium(selenium_host, selenium_port, browserId, selenium_root_url);
-
- print("bSel",bSel);
-
- bSel.start();
-
- //list comprehension to get the cartesian product
- var configurations = [{forIE:forIE,backend:backend,testPath:testPath}
- for each (forIE in project.getProperty("for-ie").split(','))
- for each (backend in backends.split(','))
- for each (testPath in Array.prototype.slice.call(scxml_tests_xml.list()))];
-
- //use pattern matching in the parameter
- configurations.forEach(function({forIE:forIE,backend:backend,testPath:testPath}){
-
- print("forIE:"+forIE+","+"backend:"+backend+","+"testPath:"+testPath);
-
- //get path to html test
- //@{for-ie}-@{backend}-@{test-path}-unit-test-html-location
- var unitTestHtmlLocationPropertyName=forIE + "-" + backend + "-" + testPath + "-in-browser-unit-test-html-location";
- var unitTestHtmlLocation = project.getProperty(unitTestHtmlLocationPropertyName);
-
- print("unitTestHtmlLocation:"+unitTestHtmlLocation);
-
- //ensure we are not testing an ie html test
- //on a non-ie browser
- if(browserName==ie_browser_name && forIE==is_for_ie ||
- browserName!=ie_browser_name && forIE==is_not_for_ie){
-
- var unitTestResult = unitTestWithSelenium(bSel,unitTestHtmlLocation,selenium_timeout);
-
- print("unitTestResult:" + unitTestResult);
-
- var unitTestResultObj = {
- data : unitTestResult,
- browser : browserName,
- scxmlTest : testPath,
- backend : backend
- };
-
- unitTestResults.push(unitTestResultObj);
-
- //report errors and failures that may occur
- if(unitTestResult.failCount || unitTestResult.errorCount){
- print("UNIT TEST ERROR");
- //TODO: add better error handling here that integrates with Ant
- }
-
- }
- });
-
- bSel.stop();
- });
-
- var totalTests = unitTestResults.reduce(function(a,b){return a + b.data.testCount},0);
- var totalTestsFailed = unitTestResults.reduce(function(a,b){return a + b.data.errorCount},0);
- var totalTestsErrored = unitTestResults.reduce(function(a,b){return a + b.data.failCount},0);
- var totalTestsPassed = unitTestResults.reduce(function(a,b){return a + b.data.testsPassed},0);
-
- print("Test Results:");
- print("Total Tests: " + totalTests);
- print("Total Tests Failed: " + totalTestsFailed);
- print("Total Tests Errored: " + totalTestsErrored);
- print("Total Tests Passed: " + totalTestsPassed);
- ]]></rhinoscript>
+ <run-unit-tests-with-selenium-macro
+ unit-tests-html-property-name="in-browser-unit-test-html-location"/>
</target>
<target name="run-unit-tests-with-rhino" depends="generate-javascript">
- <rhinoscript>
+ <rhinoscript><![CDATA[
//load requirejs
Array.prototype.slice.call(requirejs_bootstrap_paths.list()).forEach(function(requireJsPath){
load(requireJsPath);
@@ -876,9 +790,12 @@
java.lang.Thread.sleep(20);
}
- </rhinoscript>
+ ]]></rhinoscript>
</target>
+ <target name="run-all-unit-tests"
+ depends="run-unit-tests-with-selenium,run-in-browser-unit-tests-with-selenium,run-unit-tests-with-rhino" />
+
<!-- build standalone executable -->
<target name="compile-single-js">
<java classname="org.mozilla.javascript.tools.shell.Main">