Skip to content

Commit

Permalink
Merge pull request #493 from PHOENIXCONTACT/fix/legacy-test-steps
Browse files Browse the repository at this point in the history
Fix test steps in build pipeline
  • Loading branch information
seveneleven authored Nov 27, 2024
2 parents ab9d062 + 5264106 commit 2414a5a
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 59 deletions.
72 changes: 15 additions & 57 deletions .build/BuildToolkit.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -265,20 +265,7 @@ function Invoke-CoverTests($SearchPath = $RootPath, $SearchFilter = "*.csproj",
return;
}

if (-not (Test-Path $global:NUnitCli)) {
Install-Tool "NUnit.Console" $NunitVersion $global:NunitCli;
}

if (-not (Test-Path $global:OpenCoverCli)) {
Install-Tool "OpenCover" $OpenCoverVersion $global:OpenCoverCli;
}

if (-not (Test-Path $global:OpenCoverToCoberturaCli)) {
Install-Tool "OpenCoverToCoberturaConverter" $OpenCoverToCoberturaVersion $global:OpenCoverToCoberturaCli;
}

CreateFolderIfNotExists $OpenCoverReportsDir;
CreateFolderIfNotExists $NunitReportsDir;
CreateFolderIfNotExists $CoberturaReportsDir;

$includeFilter = "+[Moryx*]*";
$excludeFilter = "-[*nunit*]* -[*Tests]* -[*Model*]*";
Expand Down Expand Up @@ -309,55 +296,26 @@ function Invoke-CoverTests($SearchPath = $RootPath, $SearchFilter = "*.csproj",

ForEach($testProject in $testProjects ) {
$projectName = ([System.IO.Path]::GetFileNameWithoutExtension($testProject.Name));
$testAssembly = [System.IO.Path]::Combine($testProject.DirectoryName, "bin", $env:MORYX_BUILD_CONFIG, "$projectName.dll");
$isNetCore = Get-CsprojIsNetCore($testProject);

Write-Host "OpenCover Test: ${projectName}:";

$nunitXml = ($NunitReportsDir + "\$projectName.TestResult.xml");
$openCoverXml = ($OpenCoverReportsDir + "\$projectName.OpenCover.xml");
$coberturaXml = ($CoberturaReportsDir + "\$projectName.Cobertura.xml");

if ($isNetCore) {
$targetArgs = '"test -v ' + $env:MORYX_TEST_VERBOSITY + ' -c ' + $env:MORYX_BUILD_CONFIG + ' ' + $testProject + '"';
$openCoverAgs = "-target:$global:DotNetCli", "-targetargs:$targetArgs"
}
else {
# If assembly does not exists, the project will be build
if (-not (Test-Path $testAssembly)) {
Invoke-Build $testProject
}
Write-Host "Testing ${projectName}...";

dotnet test ${testProject} --collect:"XPlat Code Coverage" `
/p:CoverletOutputFormat="cobertura" `
/p:Include="$includeFilter" `
/p:Exclude="$excludeFilter"

$openCoverAgs = "-target:$global:NunitCli", "-targetargs:/config:$env:MORYX_BUILD_CONFIG /result:$nunitXml $testAssembly"
}
Invoke-ExitCodeCheck $LastExitCode;

$openCoverAgs += "-log:Debug", "-register:administrator", "-output:$openCoverXml", "-hideskipped:all", "-skipautoprops";
$openCoverAgs += "-returntargetcode" # We need the nunit return code
$openCoverAgs += "-filter:$includeFilter $excludeFilter"
$testsDir = [System.IO.Path]::Combine([System.IO.Path]::GetDirectoryName($testProject), "TestResults");

& $global:OpenCoverCli $openCoverAgs

$exitCode = [int]::Parse($LastExitCode);
if ($exitCode -ne 0) {
$errorText = "";
switch ($exitCode) {
-1 { $errorText = "INVALID_ARG"; }
-2 { $errorText = "INVALID_ASSEMBLY"; }
-4 { $errorText = "INVALID_TEST_FIXTURE"; }
-5 { $errorText = "UNLOAD_ERROR"; }
Default { $errorText = "UNEXPECTED_ERROR"; }
}
$testResults = Get-ChildItem -Path $testsDir -Recurse -File
foreach ($resultFile in $testResults) {
$destinationFile = $resultFile.FullName.Replace($testsDir, $CoberturaReportsDir);
$destinationPath = [System.IO.Path]::GetDirectoryName($destinationFile);

if ($exitCode -gt 0) {
$errorText = "FAILED_TESTS ($exitCode)";
}
CreateFolderIfNotExists $destinationPath;

Write-Host-Error "Nunit exited with $errorText for $projectName";
Invoke-ExitCodeCheck $exitCode;
Move-Item -Path $resultFile -Destination $destinationFile
}

& $global:OpenCoverToCoberturaCli -input:$openCoverXml -output:$coberturaXml -sources:$rootPath
Invoke-ExitCodeCheck $LastExitCode;
}
}

Expand Down
13 changes: 11 additions & 2 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ on:
branches:
- dev
- future
- release/3

env:
MORYX_OPTIMIZE_CODE: "false"
Expand Down Expand Up @@ -76,6 +77,7 @@ jobs:
with:
name: test-results
path: artifacts/Tests/
if-no-files-found: error
retention-days: 1

IntegrationTests:
Expand Down Expand Up @@ -103,8 +105,9 @@ jobs:
- name: Upload test results
uses: actions/upload-artifact@v4
with:
name: test-results
name: integration-test-results
path: artifacts/Tests/
if-no-files-found: error
retention-days: 1

Codecov:
Expand All @@ -117,10 +120,16 @@ jobs:
name: test-results
path: artifacts/Tests/

- name: Download test results
uses: actions/download-artifact@v4
with:
name: integration-test-results
path: artifacts/Tests/

- name: Codecov
uses: codecov/codecov-action@v1
with:
files: '*.OpenCover.xml'
files: '*coverage.cobertura.xml'

Documentation:
needs: [Build]
Expand Down
1 change: 1 addition & 0 deletions Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<PackageReference Update="Moq" Version="4.16.1" />
<PackageReference Update="NUnit" Version="3.13.2" />
<PackageReference Update="NUnit3TestAdapter" Version="4.1.0" />
<PackageReference Update="coverlet.collector" Version="5.8.0" />

<PackageReference Update="CommandLineParser" Version="2.8.0" />
<PackageReference Update="System.ComponentModel.Annotations" Version="4.7.0" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
<OutputType>Library</OutputType>
<TargetFramework>net5.0</TargetFramework>
<DebugType>full</DebugType>
<IsTestProject>true</IsTestProject>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="Moq" />
<PackageReference Include="NUnit" />
<PackageReference Include="NUnit3TestAdapter" />
<PackageReference Include="coverlet.collector" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 2 additions & 0 deletions src/Tests/Moryx.Container.Tests/Moryx.Container.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@
<TargetFramework>net5.0</TargetFramework>
<OutputType>Library</OutputType>
<DebugType>full</DebugType>
<IsTestProject>true</IsTestProject>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="NUnit" />
<PackageReference Include="NUnit3TestAdapter" />
<PackageReference Include="coverlet.collector" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
<TargetFramework>net5.0</TargetFramework>
<OutputType>Library</OutputType>
<DebugType>full</DebugType>
<IsTestProject>true</IsTestProject>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="Moq" />
<PackageReference Include="NUnit" />
<PackageReference Include="NUnit3TestAdapter" />
<PackageReference Include="coverlet.collector" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@
<TargetFramework>net45</TargetFramework>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<DebugType>full</DebugType>
<IsTestProject>true</IsTestProject>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="NUnit" />
<PackageReference Include="NUnit3TestAdapter" />
<PackageReference Include="coverlet.collector" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 2 additions & 0 deletions src/Tests/Moryx.Runtime.Tests/Moryx.Runtime.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
<TargetFramework>net5.0</TargetFramework>
<OutputType>Library</OutputType>
<DebugType>full</DebugType>
<IsTestProject>true</IsTestProject>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="Moq" />
<PackageReference Include="NUnit" />
<PackageReference Include="NUnit3TestAdapter" />
<PackageReference Include="coverlet.collector" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 2 additions & 0 deletions src/Tests/Moryx.Tests/Moryx.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@
<TargetFramework>net5.0</TargetFramework>
<OutputType>Library</OutputType>
<DebugType>full</DebugType>
<IsTestProject>true</IsTestProject>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="NUnit" />
<PackageReference Include="NUnit3TestAdapter" />
<PackageReference Include="coverlet.collector" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@
<TargetFramework>net45</TargetFramework>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<DebugType>full</DebugType>
<IsTestProject>true</IsTestProject>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="NUnit" />
<PackageReference Include="NUnit3TestAdapter" />
<PackageReference Include="coverlet.collector" />
</ItemGroup>

<ItemGroup>
Expand Down

0 comments on commit 2414a5a

Please sign in to comment.