【问题标题】:How to configure VS Appcenter to run xUnit tests for Xamarin/Droid如何配置 VS Appcenter 为 Xamarin/Droid 运行 xUnit 测试
【发布时间】:2019-12-10 15:39:18
【问题描述】:

基于 NUnit 的 example,可在 Appcenter github 存储库中获得,我得到了以下构建后脚本:

#!/usr/bin/env bash

echo "Found Unit test projects"
find $APPCENTER_SOURCE_DIRECTORY -regex '*.Tests*\.csproj' -exec echo {} \;
echo
echo "Run Unit test projects"
find $APPCENTER_SOURCE_DIRECTORY -regex '*.Tests*\.csproj' | xargs dotnet test --logger "trx;LogFileName=testresult.trx";

#find file with results
echo "XUnit tests result:"
pathOfTestResults=$(find $APPCENTER_SOURCE_DIRECTORY -name 'testresult.trx')
echo

grep ' \[FAIL\]' $pathOfTestResults
failures=$(grep -o ' \[FAIL\]' $pathOfTestResults | wc -l)

if [[ $failures -eq 0 ]]
then 
echo "Unit Tests passed" 
else 
echo "Unit Tests failed"
exit 1
fi

我在本地测试了脚本,它工作正常。 当 Appcenter 执行 sctipt 时,它会写入“XUnit 测试结果:”然后永远挂起。

有人在 Appcenter 中成功配置了 xUnit 测试吗?提供的脚本可能有什么问题?

【问题讨论】:

    标签: xamarin continuous-integration xunit visual-studio-app-center


    【解决方案1】:

    我现在遇到了同样的问题。问题是,由于我的 xunit 单元测试项目是针对 .NET 框架的,所以 Appcenter 构建 VM 无法运行它。我将我的单元测试项目更新为 .NET Core 2.0,它开始像魅力一样工作。

    我的观点是,单元测试运行应该是 appcenter-pre-build.sh 的一部分,因为在 apk 签名和上传后知道您的单元测试失败是没有意义的。越早越好。

    【讨论】:

    • 感谢您的回答 - 关于预构建的有效观点。我已经有针对 .net Core 2.2 的测试项目。我的问题似乎不是运行测试,而是从 trx 文件中收集结果。最后,我为运行单元测试配置了 Azure 管道。 appcenter 在这方面不走运。
    • 你能不能也检查一下包是相同的还是更高的版本。 xunit - 2.4.0,xunit.runner.visualstudio - 2.4.0,Microsoft.NET.Test.SDK - 15.9.0。如果没有,请将 nugets 更新到这些版本并重试。我能够运行 xunit 测试用例,结果从 Appcenter 本身保存在 trx 文件中。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-04
    • 1970-01-01
    相关资源
    最近更新 更多