diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 9033226..089fdfe 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -41,13 +41,13 @@ jobs: run: dotnet test --filter FullyQualifiedName!~ExampleTests --no-build --configuration Release --verbosity normal - name: Pack if: startsWith(github.ref, 'refs/tags/v') - run: dotnet pack -p:PackageVersion=${{ env.nugetVersion }} --configuration Release -o ${{github.workspace}}/IntelliTect.SelenatePack --no-build + run: dotnet pack -p:PackageVersion=${{ env.nugetVersion }} --configuration Release -o ${{github.workspace}}/IntelliTect.TestToolsPack --no-build - name: Upload Artifacts if: startsWith(github.ref, 'refs/tags/v') uses: actions/upload-artifact@v4 with: name: NuGet - path: ${{github.workspace}}/IntelliTect.SelenatePack + path: ${{github.workspace}}/IntelliTect.TestToolsPack deploy: if: startsWith(github.ref, 'refs/tags/v') @@ -55,7 +55,7 @@ jobs: needs: build-and-test environment: name: 'Production' - url: 'https://www.nuget.org/packages/IntelliTect.TestTools.Selenate' + url: 'https://www.nuget.org/packages/IntelliTect.TestTools.TestFramework' steps: - name: Download artifact from build job uses: actions/download-artifact@v4 @@ -65,11 +65,11 @@ jobs: run: | $tagVersion = "${{ github.ref }}".substring(11) echo "::set-output name=TAG_VERSION::$tagVersion" - dotnet nuget push IntelliTect.Selenate.$tagVersion.nupkg --source https://api.nuget.org/v3/index.json -k ${{ secrets.NUGET_API_KEY }} --skip-duplicate + dotnet nuget push IntelliTect.TestTools.TestFramework.$tagVersion.nupkg --source https://api.nuget.org/v3/index.json -k ${{ secrets.NUGET_API_KEY }} --skip-duplicate id: tag-version - name: Upload nupkg to Releases uses: softprops/action-gh-release@v2 with: fail_on_unmatched_files: true generate_release_notes: true - files: IntelliTect.Selenate.${{ steps.tag-version.outputs.TAG_VERSION }}.nupkg + files: IntelliTect.TestTools.TestFramework.${{ steps.tag-version.outputs.TAG_VERSION }}.nupkg diff --git a/IntelliTect.TestTools.TestFramework.Tests/TestCaseTests/TestFailureTests.cs b/IntelliTect.TestTools.TestFramework.Tests/TestCaseTests/TestFailureTests.cs index 1e9af68..80702bf 100644 --- a/IntelliTect.TestTools.TestFramework.Tests/TestCaseTests/TestFailureTests.cs +++ b/IntelliTect.TestTools.TestFramework.Tests/TestCaseTests/TestFailureTests.cs @@ -41,5 +41,18 @@ public async Task DependencyWithMissingDependencyThrowsOriginalError() Assert.IsType(ex.InnerException); Assert.Contains("oops", ex.InnerException!.Message, StringComparison.InvariantCultureIgnoreCase); } + + [Fact] + public async Task AsyncBlockThrowsProperlyCatchAndLogException() + { + TestCase tc = new TestBuilder() + .AddAsyncTestBlock() + .Build(); + + var ex = await Assert.ThrowsAsync(() => tc.ExecuteAsync()); + Assert.False(tc.Passed); + var invalidOp = Assert.IsType(ex.InnerException); + Assert.Contains("oops", invalidOp.Message, StringComparison.InvariantCultureIgnoreCase); + } } } diff --git a/IntelliTect.TestTools.TestFramework.Tests/TestData/TestBlocks/SingleDependencyBlocks.cs b/IntelliTect.TestTools.TestFramework.Tests/TestData/TestBlocks/SingleDependencyBlocks.cs index b26c1c8..c2563d6 100644 --- a/IntelliTect.TestTools.TestFramework.Tests/TestData/TestBlocks/SingleDependencyBlocks.cs +++ b/IntelliTect.TestTools.TestFramework.Tests/TestData/TestBlocks/SingleDependencyBlocks.cs @@ -1,5 +1,6 @@ using IntelliTect.TestTools.TestFramework.Tests.TestData.Dependencies; using System; +using System.Threading.Tasks; using Xunit; namespace IntelliTect.TestTools.TestFramework.Tests.TestData.TestBlocks @@ -70,4 +71,13 @@ public bool Execute(SomeDependency dep) return true; } } + + public class AsyncError : TestBlock + { + public async Task Execute() + { + await Task.Delay(1); + throw new InvalidOperationException("Oops"); + } + } } diff --git a/IntelliTect.TestTools.TestFramework/TestCase.cs b/IntelliTect.TestTools.TestFramework/TestCase.cs index 609cc94..7b42dc8 100644 --- a/IntelliTect.TestTools.TestFramework/TestCase.cs +++ b/IntelliTect.TestTools.TestFramework/TestCase.cs @@ -94,12 +94,9 @@ public async Task ExecuteAsync() bool runSuccess = await TryRunBlock(tb, testBlockInstance, executeArgs); if (!runSuccess) { - if (TestBlockException is null) - { - TestBlockException = new( + TestBlockException ??= new( $"Unknown error occurred while running test block {tb}. " + "Please file an issue: https://github.com/IntelliTect/TestTools.TestFramework/issues"); - } break; } } @@ -122,6 +119,10 @@ public async Task ExecuteAsync() if (TestBlockException is null) { + // Note: This likely needs to be moved up above the finally blocks. + // If a test case "passes" i.e. finishes all of its test blocks, we probably need to know that + // in the finally blocks. + // Need to think about how to handle "passed" state if a finally block fails. Passed = true; Log?.Info("Test case finished successfully."); } @@ -405,17 +406,17 @@ private async Task TryRunBlock(Block block, object blockInstance, List FinallyBlockExceptions.Add(ex.InnerException) ); } - catch (ArgumentException ex) + catch (TargetParameterCountException ex) { + ex.Data.Add("AdditionalInfo", "Test block failed: Mismatched count between Execute method arguments and supplied dependencies."); HandleFinallyBlock( block, () => TestBlockException = ex, () => FinallyBlockExceptions.Add(ex) ); } - catch (TargetParameterCountException ex) + catch (Exception ex) { - ex.Data.Add("AdditionalInfo", "Test block failed: Mismatched count between Execute method arguments and supplied dependencies."); HandleFinallyBlock( block, () => TestBlockException = ex,