1

Based on example for NUnit, available in Appcenter github repository I got following post-build script:

#!/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

I tested script locally, it works fine. When sctipt executed by Appcenter, it writes "XUnit tests result:" and then hangs forever.

Did anyone succeeded with configuring xUnit tests in Appcenter? What could be wrong in provided script?

Andris
  • 1,262
  • 1
  • 15
  • 24

1 Answers1

0

I had faced the same issue now. The problem is that since my xunit unit test project was targeted for .NET framework, Appcenter build VM was not able to run it. I updated my unit test project to .NET Core 2.0 and it started working like a charm.

My view is that the unit test run should be part of appcenter-pre-build.sh since getting to know that your unit tests are failing after the apk is signed and uploaded makes no sense. As early is better.

  • Thank you for your answer - valid point about pre build. I already have my test project targeted to .net Core 2.2. My problem seems not with running tests, but with collecting results from trx file. At the end I've configured Azure pipeline for running unit tests. No luck with appcenter for this. – Andris Jan 23 '20 at 10:05
  • Can you also check if the packages are of the same or higher version. xunit - 2.4.0, xunit.runner.visualstudio - 2.4.0, Microsoft.NET.Test.SDK - 15.9.0. If not, please update the nugets to these version and retry. I was able to run the xunit test cases and results are getting persisted in the trx file from Appcenter itself. – Sreejith Vijayan Jan 27 '20 at 10:42