Skip to content

Instantly share code, notes, and snippets.

@felipebaltazar
Created October 1, 2019 13:36
Show Gist options
  • Save felipebaltazar/38c4ea4f6ecfafafd262a859ca7db59b to your computer and use it in GitHub Desktop.
Save felipebaltazar/38c4ea4f6ecfafafd262a859ca7db59b to your computer and use it in GitHub Desktop.
NUnit tests on app center
#!/usr/bin/env bash
#
# For Xamarin, run all NUnit test projects that have "Test" in the name.
# The script will build, run and display the results in the build logs.
echo ""
echo "=============================================================================="
echo "Task : Unit Tests"
echo "Description : Run unit tests and print results."
echo "Version : 1.0.0"
echo "Author : Felipe baltazar"
echo "Help : [More Information](https://github.com/felipebaltazar)"
echo "=============================================================================="
echo ""
echo "Building NUnit test projects:"
find $APPCENTER_SOURCE_DIRECTORY -regex '.*Test.*\.csproj' -exec msbuild {} \;
echo
echo "Running NUnit tests:"
find $APPCENTER_SOURCE_DIRECTORY -regex '.*bin.*Tests.dll' -exec dotnet vstest /logger:"trx;LogFileName=TestResult.trx" {} +
echo
echo "NUnit tests result:"
pathOfTestResults=$(find $APPCENTER_SOURCE_DIRECTORY -name 'TestResult.trx')
cat $pathOfTestResults
echo
#look for a failing test
grep -q 'failed="0"' $pathOfTestResults
if [[ $? -eq 0 ]]
then
echo ""
echo "All tests passed!! ๐Ÿ’ช๐ŸŽ‰๐ŸŽ‰๐Ÿš€"
else
echo ""
echo "One or more test Failed!! ๐Ÿ˜จ๐Ÿ™€"
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment