Note: This guide shows how to automate unit testing and results publishing to Deki in Windows Server 2003. Clearly, some refactoring would be beneficial; this was completed a piece at a time as new functionality was requested or needed.
This assumes curl.exe, nunit-summary.exe, wget.exe, and the batch files/scripts below exist in c:\wget (with appropriate permissions). It also assumes that NUnit 2.4.8 has been installed, and that msbuild.exe exists in C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\ in order to compile the unit tests. Also, to allow for some some idiosyncracies involving calling Cygwin scripts from a batch file, separate batch files are needed to complete the Linux 'sed' calls.
To kick off the testing (in this case for trunk), create a scheduled task to run c:\wget\msi.cmd.
Contents of msi.cmd:
wget -r http://nightlybuild.mindtouch.com/Windows_MSI/ -R *.rpm,*.deb,*.gif,*.html,*.gz,"*Vista*","*index*","*Linux*","*sources*","*submitted*" -o c:\wget\logs\downloadlog.log
del c:\wget\nightlybuild.mindtouch.com\Windows_MSI\MindTouch_Deki_8*
unzip c:\wget\nightlybuild.mindtouch.com\Windows_MSI\*.zip -d c:\wget\nightlybuild.mindtouch.com\Windows_MSI\
ren c:\wget\nightlybuild.mindtouch.com\Windows_MSI\*.msi 2k3.msi
msiexec.exe /I "c:\wget\nightlybuild.mindtouch.com\Windows_MSI\2k3.msi" /qn /lwamoxe c:\wget\logs\install.log ALLUSERS=1
call c:\wget\installdeki.bat
svn co https://svn.mindtouch.com/source/public/dekiwiki/trunk/src/tests/DekiMisc/ c:\wget\compile\
copy /Y "c:\Program Files\MindTouch\MindTouch Deki\api\bin\mindtouch.dream.dll" c:\wget\compile\
call sedCsproj.bat
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\msbuild c:\wget\compile\mindtouch.deki.tests.csproj /target:build /noconsolelogger
call c:\wget\unitRename.bat
copy /Y c:\bin\* "c:\program files\mindtouch\mindtouch deki\api\bin\"
"C:\Program Files\NUnit 2.4.8\bin\nunit-console" "c:\program files\mindtouch\mindtouch deki\api\bin\mindtouch.deki.nunit"
C:\wget\nunit-summary.exe -xsl=transform.xslt -o=c:\wget\nunit-results.html
call cleanHTML.bat
for /F "tokens=1-5 delims=/ " %%d in ('date /t') do set dt=%%e-%%f-%%g
for /F "tokens=1-5 delims=/ " %%d in ('date /t') do set cy=%%g
curl -c c:\wget\cookies.txt http://USERNAME:PASSWORD@wiki.developer.mindtouch.com/@api/deki/users/authenticate
curl -v -b c:\wget\cookies.txt -d "@nunit-results.html" http://wiki.developer.mindtouch.com/@api/deki/pages/=Sandbox%%252FMindTouch%%2BDaily%%2BTesting%%252F"%cy%"%%252F"%dt%"%%252FTrunk%%253A%%2BWindows%%2B-%%2BUnit%%2BTesting/contents
Contents of installDeki.bat:
curl -X POST -d "SiteLang=en-us&Sitename=MindTouch+Deki&SysopName=Admin&SysopPass=password&SysopPass2=password&SysopEmail=nightlybuilds@mindtouch.com&RegistrarName=asdf&RegistrarPhone=1231234123&RegistrarNewsletter=1&DBserver=localhost&DBname=wikidb&DBuser=wikiuser&RootUser=root&RootPW=password&useroot=1&ApiKey=9BL9WSqql8lSDeLKXSgXYxGYJt44LLYM&Mono=%2Fusr%2Fbin%2Fmono&ImageMagickConvert=%2Fusr%2Fbin%2Fconvert&ImageMagickIdentify=%2Fusr%2Fbin%2Fidentify&prince=%2Fusr%2Fbin%2Fprince" http://localhost/config/index.php
Contents of sedCsproj.bat:
c:\cygwin\bin\bash --login -i -c c:/wget/changeProj.sh
Contents of changeProj.sh:
sed -i -e 's|..\\..\\redist\\nunit\\|c\:\\wget\\compile\\|' /cygdrive/c/wget/compile/mindtouch.deki.tests.csproj sed -i -e 's|..\\..\\redist\\|c:\\wget\\compile\\|' /cygdrive/c/wget/compile/mindtouch.deki.tests.csproj sed -i -e 's|http\:\/\/192.168.2.115/\@api|http\:\/\/NEW_IP/\@api\/|' /cygdrive/c/wget/compile/Utils.cs sed -i -e s'|:8081|\/\@api|' /cygdrive/c/wget/compile/Utils.cs exit
Contents of unitRename.bat:
c:\cygwin\bin\bash --login -i -c c:/wget/unitRename.sh
Contents of unitRename.sh:
sed -i -e 's|test|tests|' /cygdrive/c/bin/mindtouch.deki.nunit exit
Contents of transform.xslt:
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method='html' indent='yes'/>
<xsl:template match="/">
<html>
<xsl:apply-templates/>
</html>
</xsl:template>
<xsl:template match="test-results">
<head>
<script type="text/javascript">
function ShowHideDetails(contentControlId)
{
var contentControl = document.getElementById(contentControlId);
if(contentControl)
{
if(contentControl.style.display == 'none')
{
contentControl.style.display = '';
}
else
{
contentControl.style.display = 'none';
}
}
}
</script>
</head>
<body>
<div id="uxHeader" style="font-weight:bold;">
Tests run: <xsl:value-of select="@total"/>, Failures: <xsl:value-of select="@failures"/>, Not run: <xsl:value-of select="@not-run"/>, Time: <xsl:value-of select="test-suite/@time"/> seconds
</div>
<xsl:if test="//test-case[@success = 'False']">
<div style="font-weight:bold;margin-top:10px;border-top:1px solid black;font-size:14pt;">
Failed Tests
</div>
<xsl:for-each select="//test-suite">
<xsl:if test="results/test-case[@success = 'False']">
<div style="margin-top:5px;font-weight:bold;"><xsl:value-of select="@name" /></div>
<div style="margin-left:10px;">
<xsl:call-template name="failureTemplate"></xsl:call-template>
</div>
</xsl:if>
</xsl:for-each>
</xsl:if>
<xsl:if test="//test-case[@executed = 'False']">
<div style="font-weight:bold;margin-top:10px;border-top:1px solid black;font-size:14pt;">
Ignored Tests
</div>
<xsl:for-each select="//test-suite">
<xsl:if test="results/test-case[@executed = 'False']">
<div style="margin-top:5px;font-weight:bold;"><xsl:value-of select="@name" /></div>
<div style="margin-left:10px;">
<xsl:call-template name="ignoreTemplate"></xsl:call-template>
</div>
</xsl:if>
</xsl:for-each>
</xsl:if>
<div style="font-weight:bold;margin-top:10px;border-top:1px solid black;font-size:14pt;">
Successful Tests
</div>
<xsl:for-each select="//test-suite">
<xsl:if test="results/test-case[@success = 'True']">
<div style="margin-top:5px;font-weight:bold;"><xsl:value-of select="@name" /></div>
<div style="margin-left:10px;">
<xsl:call-template name="passTemplate"></xsl:call-template>
</div>
</xsl:if>
</xsl:for-each>
</body>
</xsl:template>
<xsl:template match="results/test-case[failure]" name="failureTemplate">
<xsl:for-each select="results/test-case[@success = 'False']">
<span style="font-weight:bold;font-size:12pt;">
<xsl:value-of select="position()"/>)
</span>
<xsl:value-of select="@name"/>
<div style="font-size:10pt;margin-left:25px;">Reason:
<xsl:choose><xsl:when test="string-length(child::node()/message)=0"> [not defined]</xsl:when>
<xsl:otherwise> "<xsl:value-of select="child::node()/message"/>"</xsl:otherwise>
</xsl:choose>
</div>
</xsl:for-each>
</xsl:template>
<xsl:template match="results/test-case[reason]" name="ignoreTemplate">
<xsl:for-each select="results/test-case[@executed = 'False']">
<span style="font-weight:bold;font-size:12pt;">
<xsl:value-of select="position()"/>)
</span>
<xsl:value-of select="@name"/>
<div style="font-size:10pt;margin-left:25px;">Reason:
<xsl:choose><xsl:when test="string-length(child::node()/message)=0"> Ignored </xsl:when>
<xsl:otherwise> "<xsl:value-of select="child::node()/message"/>"</xsl:otherwise>
</xsl:choose>
</div>
</xsl:for-each>
</xsl:template>
<xsl:template match="results[test-case]" name="passTemplate">
<xsl:for-each select="results/test-case[@success = 'True']">
<span style="font-weight:bold;font-size:12pt;">
<xsl:value-of select="position()"/>)
</span>
<xsl:value-of select="@name"/>
<div style="font-size:10pt;margin-left:25px;">Reported: Success
</div>
<xsl:text></xsl:text>
</xsl:for-each>
</xsl:template>
<xsl:template name="Newline"><xsl:text>
</xsl:text></xsl:template>
</xsl:stylesheet>
Contents of cleanHTML.bat:
c:\cygwin\bin\bash --login -i -c c:/wget/cleanHTML.sh
Contents of cleanHTML.sh:
sed -i '1,38d' /cygdrive/c/wget/nunit-results.html sed -i -e :a -e '$d;N;1,6ba' -e 'P;D' /cygdrive/c/wget/nunit-results.html exit
| Images 0 | ||
|---|---|---|
| No images to display in the gallery. |
Copyright © 2011 MindTouch, Inc. Powered by