Search code examples
nantwatin

Watin with Nant example


Can you give me a simple example of nant build file which builds watin/nunit tests from .csproj file with all needed dependencies?


Solution

  • Here is my nant build file which I finally designed for my project:

    <?xml version="1.0"?>
    <project name="WatInTests" default="test">
      <include buildfile="common.properties" />
      <include buildfile="properties_watin.properties" />
      <property name="run.dir" value="${jenkins.jobs.dir}\<my_project>\workspace" />     
      <property name="currentFileset" value="${projectFileset}"/>
      <property name="precondition.test" value="${currentFileset}.Tests.PreconditionTest"/>
      <property name="results.folder" value="${results.dir}\${now.datetime}"/>  
    
      <target name="clean">  
       <delete verbose="true">
         <fileset basedir="${project.build.dir}">
           <include name="**\*" />
         </fileset>
       </delete>
    <copy file="App.config" 
            tofile="${uitests.dir}\${currentFileset}\App.config" inputencoding="utf-8" 
            outputencoding="utf-8" overwrite="true">
                <filterchain>
                    <expandproperties />
                </filterchain>
            </copy>
      </target>
      <target name="build" depends="clean">
                    <echo message="Start building ${currentFileset}"/>
                    <copy file="${nunit.reference}" todir="${uitests.dir}\${currentFileset}\bin\debug" failonerror="true"/>                
                    <copy file="${nunit_core.reference}" todir="${uitests.dir}\${currentFileset}\bin\debug" failonerror="true"/>
                    <exec program="${project.utils.msbuild.exe}" workingdir="${uitests.dir}\${currentFileset}">
                              <arg value="${ProjectSlnPath}"></arg>                                 
                              <arg value="/p:Configuration=${BuildMode}"></arg>
                    </exec>
                    <echo message="Build succeeded"/>
                    <echo message="Copy build to ${run.dir}"/>
                    <copy todir="${run.dir}" overwrite="true">
                      <fileset basedir="${watintests.dir}\${currentFileset}\bin\debug">
                           <exclude name="*.svn" />
                      </fileset>
                    </copy>
       </target>
    
      <target name="precondition" depends="build">
         <mkdir dir="${results.folder}" />
         <exec program="${nunit.file}" failonerror="true" verbose="true" workingdir="${run.dir}">
                    <arg value="/run:${precondition.test}" />
                    <arg value="${run.dir}\${nunit.config.file}" />
         </exec>     
      </target>
      <target name="test" depends="precondition">
         <exec program="${nunit.file}" verbose="true" workingdir="${run.dir}"> 
                    <arg value="/exclude:Precondition" />               
                    <arg value="${run.dir}\${nunit.config.file}" />
         </exec>
         <copy file="${run.dir}\TestResult.xml" todir="${results.folder}" failonerror="true"/>
    </target>
    </project>