Search code examples
asp.net-mvc-4unit-testingnant

Can I run test project using NAnt without NUnit


I have created test project in MVC for unit testing without using NUnit.

Can I use NAnt to run this project?

If no what is the suitable method to automatically run test cases (if possible sequentially)?


Solution

  • You don't have to use NUnit. If you already created a Unit test project in MVC you can use use command line to run this through nant.

    From my understanding, you rather just execute the unit test poject you have in your solution which provide you with your test results. If that's the case then all you need to do it run that project using the msbuild command line. If you can run anything on command line chances are you can do the same in NAnt.

    Here is how that translate to NAnt.

    Example:

    <target name="run.unittest.project" >
    <property name="msbuild" value="C:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe"/>
    <property name="configuration" value="Debug" />
    
    <exec program="${msbuild}" commandline="YourSolution.sln /p:Configuration:${configuration};Platform=OurPlatform /t:Project_Name"/>
    
    </target>
    

    But....If you wanted to run a NUint test on a specific assembly in NANT you can try this...

    <target name="nunit.target" description="" >    
    
    <property name="UnitTests" value="Path\project\bin\${configuration}" />
    
    <echo message="Starting the UnitTests ....." />
    <nunit2>
        <formatter type="Plain" />
        <test assemblyname="UnitTests.dll" appconfig="UnitTests.dll.config" />
    </nunit2>
    </target>