TeamCity NUnit集成失败 - 总是得到“无法找到程序集nunit.framework ......”!

时间:2010-08-16 06:19:48

标签: nunit nant teamcity

我正在尝试让TeamCity按照以下方式在NAnt脚本中设置运行NUnit测试:

<nunit2>
    <formatter  type="Xml"
                usefile="true"
                extension=".xml"
                outputdir="${BuildArea.ReportsDir}" />

    <test   assemblyname="${BuildArea.OutputDir}\Common.Tests.dll"
            appconfig="src\Common.Tests\Tests.config" />       
</nunit2>

从buildserver / agent机器上的命令行手动运行构建脚本运行测试就好了,所以我知道构建脚本本身没有问题。但是,当构建在TeamCity中运行时,我总是会收到错误:

“无法找到程序集nunit.Framework”

我遇到了一个相关的帖子(http://devnet.jetbrains.net/message/5211436#5211436),它建议将nunit.framework放在与包含测试的dll相同的位置,但我已经这样做了,我仍然得到同样的错误。无法安装到GAC。

任何人都知道如何解决这个问题?我花了好几个小时试图找出可能出现的问题,但我看不出我的错误。

由于

确切的错误和堆栈跟踪如下:

[23:48:02]:启动TeamCity NUnit Test Runner

[23时48分02秒]:

NUnit错误:System.IO.FileNotFoundException:无法加载文件或程序集'nunit.framework,Version = 2.4.8.0,Culture = neutral,PublicKeyToken = 96d09a1eb7f44a77'或其依赖项之一。该系统找不到指定的文件。 文件名:'nunit.framework,Version = 2.4.8.0,Culture = neutral,PublicKeyToken = 96d09a1eb7f44a77'

服务器堆栈跟踪: 在System.Reflection.Assembly._nLoad(AssemblyName fileName,String codeBase,Evidence assemblySecurity,Assembly locationHint,StackCrawlMark&amp; stackMark,Boolean throwOnFileNotFound,Boolean forIntrospection) 在System.Reflection.Assembly.nLoad(AssemblyName fileName,String codeBase,Evidence assemblySecurity,Assembly locationHint,StackCrawlMark&amp; stackMark,Boolean throwOnFileNotFound,Boolean forIntrospection) 在System.Reflection.Assembly.InternalLoad(AssemblyName assemblyRef,Evidence assemblySecurity,StackCrawlMark&amp; stackMark,Boolean forIntrospection) 在System.Reflection.Assembly.Load(AssemblyName assemblyRef) 在NUnit.Core.TestFramework.FromAssembly(装配程序集) at NUnit.Core.Builders.TestAssemblyBuilder.Load(String path) 在NUnit.Core.Builders.TestAssemblyBuilder.Build() 在NUnit.Core.Builders.TestAssemblyBuilder.Build(String testName) at NUnit.Core.TestSuiteBuilder.Build(String assemblyName,String testName) at NUnit.Core.SimpleTestRunner.Load(String assemblyName,String testName) at NUnit.Core.SimpleTestRunner.Load(String assemblyName) at NUnit.Core.ProxyTestRunner.Load(String assemblyName) at NUnit.Core.ProxyTestRunner.Load(String assemblyName) 在System.Runtime.Remoting.Messaging.StackBuilderSink._PrivateProcessMessage(IntPtr md,Object [] args,Object server,Int32 methodPtr,Boolean fExecuteInContext,Object []&amp; outArgs) 在System.Runtime.Remoting.Messaging.StackBuilderSink.PrivateProcessMessage(RuntimeMethodHandle md,Object [] args,Object server,Int32 methodPtr,Boolean fExecuteInContext,Object []&amp; outArgs) 在System.Runtime.Remoting.Messaging.StackBuilderSink.SyncProcessMessage(IMessage msg,Int32 methodPtr,Boolean fExecuteInContext)

在[0]处重新抛出异常: 在System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg,IMessage retMsg) 在System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData&amp; msgData,Int32 type) at NUnit.Core.TestRunner.Load(String assemblyName) at JetBrains.TeamCity.NUnitLauncher.NUnitRunner.LoadTest(String testAssembly,String testName,TestRunner runner)c:\ Agent \ work \ e34bdcb45e12f223 \ src \ NUnitLauncher \ src \ NUnit-2.2 \ NUnitRunner.cs:第33行 at c:\ Agent \ work \ e34bdcb45e12f223 \ src \ NUnitLauncher \ src \ AssemblyTest.cs中的JetBrains.TeamCity.NUnitLauncher.AssemblyTest.LoadTestDomain():第71行 在JetBrains.TeamCity.NUnitLauncher.LoadTestDomainAction.Action(AssemblyTest test)中的c:\ Agent \ work \ e34bdcb45e12f223 \ src \ NUnitLauncher \ src \ LoadTestDomainAction.cs:第14行 at c:\ Agent \ work \ e34bdcb45e12f223 \ src \中的JetBrains.TeamCity.NUnitLauncher.TryOneAssemblyTest.Action()NUnitLauncher \ src \ TryOneAssemblyTest.cs:第18行 at JetBrains.TeamCity.NUnitLauncher.TryOneAssembly.Do()in c:\ Agent \ work \ e34bdcb45e12f223 \ src \ NUnitLauncher \ src \ TryOneAssembly.cs:第31行

1 个答案:

答案 0 :(得分:0)

在你的跑步者属性页面中,你有没有将Nant置于家中?我们使用%env.NANTHOME%。请注意,它区分大小写。

我们还必须为teamcity创建一个单独的单元测试目标,因此我们调用目标:clean compile run-unit-tests-teamcity。

下面是我们目标的提取,整理了一下。

<target name="run-unit-tests">  
    <property name="test.executable" value="tools\nunit\nunit-console.exe"/>
    <property name="test.args" value="${test.assemblies} /xml=&quot;${build.fullpath}\test-reports\${prefix}_UnitTests.xml&quot; /nologo /exclude=WetTest" dynamic="true"/>     
    <call target="do-unit-tests"/>
</target>

<target name="run-unit-tests-teamcity"> 
    <property name="test.executable" value="${teamcity.dotnet.nunitlauncher}"/> 
    <property name="test.args" value="v2.0 MSIL NUnit-2.4.6 /category-exclude:WetTest ${test.assemblies}" dynamic="true"/>      
    <call target="do-unit-tests"/>
</target>

<!-- Run each of the unit tests in their own directory by project-->
<target name="do-unit-tests">

    <!-- Run the unit tests for component1 -->
    <property name="prefix" value="${prefix.component1}"/>
    <property name="test.assemblies" value="component1.Common.dll  component1.a.dll component1.b.dll component1.c.dll etc.dll"/>
    <property name="test.assembly.dir" value="${build.dir}\${prefix.component1}" />
    <call target="do-unit-test-single-project" />

    <!-- Run the unit tests for component2 -->
    <property name="prefix" value="${prefix.component2}"/>
    <property name="test.assemblies" value="component2.Common.dll  component2.a.dll component2.b.dll component2.c.dll etc.dll"/>
    <property name="test.assembly.dir" value="${build.dir}\${prefix.component2}" />
    <call target="do-unit-test-single-project" />

</target>

<target name="do-unit-test-single-project">

    <mkdir dir="${build.dir}\test-reports" />

    <!-- Ensure all tests have the default test config -->
    <copy file="${build.dir}\${prefix.component1}\Tests.config" tofile="${test.assembly.dir}\Tests.config" />

    <echo message="Starting NUnit code coverage run..."/>
    <property name="test.failed" value="false"/>

    <trycatch>
        <try>
            <ncover program="${path::get-full-path('tools\NCover\NCover.Console.exe')}"
                    commandLineExe="${test.executable}"
                    commandLineArgs="${test.args}"
                    workingDirectory="${build.dir}\${prefix}"
                    coverageFile="${build.fullpath}\test-reports\${prefix}_Coverage.xml"
                    logFile="${build.fullpath}\test-reports\${prefix}_coverage.log"
                    >
                    <assemblies basedir="${build.dir}\${prefix}">
                        <include name="${test.assemblies}"/> <!-- Only create the coverage for the specific project's assemblies -->
                    </assemblies>
            </ncover>
        </try>
        <catch property="failure">
            <echo message="At least one test failed: ${failure}"/>
            <property name="fail.message" value="${failure}"/>
            <property name="test.failed" value="true"/>
        </catch>
    </trycatch>

    <call target="create-coverage-report"/>
</target>

<target name="create-coverage-report">
    <ncoverexplorer program="tools\NCoverExplorer\NcoverExplorer.Console.exe"
                    projectName="NCoverExplorer"
                    reportType="4"
                    outputDir="${build.dir}\test-reports" 
                    xmlReportName="${prefix}_CoverageReport.xml"
                    htmlReportName="${prefix}_CoverageReport.html" 
                    mergeFileName="${prefix}_CoverageMerge.xml"
                    showExcluded="True"
                    satisfactoryCoverage="80" >
        <fileset basedir="${build.dir}\test-reports">
            <include name="${prefix}_Coverage.xml"/> <!-- Create a coverage report for each project group-->
        </fileset>
        <exclusions>
            <exclusion type="Namespace" pattern="*.Tests" />
        </exclusions>
    </ncoverexplorer>
</target>