我有一个Xamarin项目,我经常将其推送到构建它的Appcenter。效果很好,但是现在我在解决方案中添加了NUnit 3测试,尽管它们在本地执行得很好,但似乎在Appcenter构建期间不会执行。
我如何配置解决方案,以便在Appcenter上执行测试项目?似乎需要combine it with Xamarin.UITest,但我真的不明白为此需要采取哪些步骤。请注意,我的NUnit测试不是UI测试,它们是普通的单元测试。
[我发现让AppCenter运行项目的NUnit测试的最简单方法是为每个应用程序添加构建后脚本,然后将NunitXml.TestLogger
Nuget程序包安装到您的NUnit项目中,这将输出测试结果的Xml文件。] >
要创建构建后脚本,它必须位于Android / iOS .csproj的根目录中,并命名为appcenter-post-build.sh
。然后您的脚本应如下所示:
#Android post build script #Make sure the directly to the NUnit csproj is correct ProjectPath="$APPCENTER_SOURCE_DIRECTORY\YourProject.NUnit\YourProject.NUnit.csproj" echo "$ProjectPath" #To generate the xml file it requires nuget NunitXml.TestLogger dotnet test "$APPCENTER_SOURCE_DIRECTORY" --logger:"nunit;LogFilePath=TestResults.xml" echo "NUnit tests result:" pathOfTestResults=$(find $APPCENTER_SOURCE_DIRECTORY -name 'TestResults.xml') cat $pathOfTestResults echo #Looks for a failing test and causes the build to fail if found grep -q 'result="Failed"' $pathOfTestResults if [[ $? -eq 0 ]] then echo "A test Failed" exit 1 else echo "All tests passed" fi
如果测试失败,最后一部分将导致您的AppCenter构建失败。另外,您可能需要尝试在AppCenter中对其进行两次构建,然后才能发现已将构建后脚本添加到您的存储库中。