2

我的 .Net Web 应用程序的顶层有代码,我想对其进行单元测试,但是当我的构建服务器使用 aspnet_compiler.exe 编译项目时,它会生成一个完全不能被其他人使用的 .dll 文件项目,即一个 NUnit 测试项目。

(对于 ASP .Net Web 应用程序和 ASP .Net MVC 应用程序也是如此。)

我在这里做错了吗?这是我的调用编译器的 NAnt 脚本...

<exec program="${asp.compiler.home}/aspnet_compiler.exe" failonerror="true">
   <arg value="-nologo"/>
   <arg value="-c"/>
   <arg value="-f"/>
   <arg value="-errorstack"/>
   <arg value="-v"/>
   <arg value="${project.name}"/>
   <arg value="-p"/>
   <arg value="${project::get-base-directory()}"/>
   <arg value="${web.deploy.dir}\${project.name}"/>
  </exec>
4

4 回答 4

4

我在 .Net Web 应用程序的顶层有代码,我想对其进行单元测试 [...]

停在那儿; 那就是问题所在。将该代码放入帮助程序中,并在 ASP.NET 之外对其进行测试。

于 2009-10-15T13:38:53.147 回答
3

您不需要使用 aspnet_compiler.exe。这只是一个实用程序,用于预编译您的 aspx 页面,以避免用户第一次点击页面时出现启动滞后。

据我了解,在构建您的解决方案时,您的 ASP.NET MVC Web 应用程序中的任何非 aspx/ascx 代码都将正常编译为 DLL。然后,您的 NUnit 测试项目可以使用此 DLL。我认为这是您要测试的那些位。

因此,只需使用来自 NAnt 的 MSBuild 构建项目,而无需考虑 aspnet_compiler.exe。

于 2009-10-21T21:54:30.660 回答
1

你不能在这里运行类似的东西,而不是在 Nant 作为构建后事件吗?

C:\Windows\Microsoft.NET\Framework\v2.0.50727\aspnet_compiler -v / -p "$(SolutionDir)\PathToMyWebProject"

(其中 FilePathToMyWebProject 是项目文件相对于解决方案文件的路径)

于 2009-10-14T20:21:56.957 回答
0

我们使用带有构建文件的 MSBuild 来编译 Web 应用程序并运行测试,如果您可以跳过 NAnt 的内容,这里是构建文件中的一个相关部分(作为 MSbuild.exe 的参数调用):

<!-- Build projects by calling the Project files generated by VS -->
  <Target Name="Build">
    <MSBuild Projects="$(ProjectFile)" />
    <MSBuild Projects="$(TestProjectFile)" />
  </Target>

  <!-- Run Unit tests -->
  <Target Name="Test" DependsOnTargets="Build">
    <CreateItem Include="ClearViewTest\Bin\Debug\ClearViewTest.exe">
      <Output TaskParameter="Include" ItemName="ClearViewTest" />
    </CreateItem>
    <NUnit Assemblies="@(ClearViewTest)" ToolPath="C:\Program Files\NUnit 2.4\bin" ContinueOnError="false" OutputXmlFile="SoultionTestResults.xml" />
  </Target>
于 2009-10-14T20:26:34.473 回答