Skip to content

Commit e2a0755

Browse files
PandaMagnusKeboo
andauthored
Fix for when an async block throws (#74)
* Fix for when an async block throws * Fix the build (didn't need Playwright) * Some cleanup and fixes to deploy.yml * Rename test to what it actually does * Save off variable from Assert.IsType Co-authored-by: Kevin B <[email protected]> --------- Co-authored-by: Kevin B <[email protected]>
1 parent c0453ff commit e2a0755

File tree

4 files changed

+36
-12
lines changed

4 files changed

+36
-12
lines changed

.github/workflows/deploy.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,21 +41,21 @@ jobs:
4141
run: dotnet test --filter FullyQualifiedName!~ExampleTests --no-build --configuration Release --verbosity normal
4242
- name: Pack
4343
if: startsWith(github.ref, 'refs/tags/v')
44-
run: dotnet pack -p:PackageVersion=${{ env.nugetVersion }} --configuration Release -o ${{github.workspace}}/IntelliTect.SelenatePack --no-build
44+
run: dotnet pack -p:PackageVersion=${{ env.nugetVersion }} --configuration Release -o ${{github.workspace}}/IntelliTect.TestToolsPack --no-build
4545
- name: Upload Artifacts
4646
if: startsWith(github.ref, 'refs/tags/v')
4747
uses: actions/upload-artifact@v4
4848
with:
4949
name: NuGet
50-
path: ${{github.workspace}}/IntelliTect.SelenatePack
50+
path: ${{github.workspace}}/IntelliTect.TestToolsPack
5151

5252
deploy:
5353
if: startsWith(github.ref, 'refs/tags/v')
5454
runs-on: ubuntu-latest
5555
needs: build-and-test
5656
environment:
5757
name: 'Production'
58-
url: 'https://www.nuget.org/packages/IntelliTect.TestTools.Selenate'
58+
url: 'https://www.nuget.org/packages/IntelliTect.TestTools.TestFramework'
5959
steps:
6060
- name: Download artifact from build job
6161
uses: actions/download-artifact@v4
@@ -65,11 +65,11 @@ jobs:
6565
run: |
6666
$tagVersion = "${{ github.ref }}".substring(11)
6767
echo "::set-output name=TAG_VERSION::$tagVersion"
68-
dotnet nuget push IntelliTect.Selenate.$tagVersion.nupkg --source https://api.nuget.org/v3/index.json -k ${{ secrets.NUGET_API_KEY }} --skip-duplicate
68+
dotnet nuget push IntelliTect.TestTools.TestFramework.$tagVersion.nupkg --source https://api.nuget.org/v3/index.json -k ${{ secrets.NUGET_API_KEY }} --skip-duplicate
6969
id: tag-version
7070
- name: Upload nupkg to Releases
7171
uses: softprops/action-gh-release@v2
7272
with:
7373
fail_on_unmatched_files: true
7474
generate_release_notes: true
75-
files: IntelliTect.Selenate.${{ steps.tag-version.outputs.TAG_VERSION }}.nupkg
75+
files: IntelliTect.TestTools.TestFramework.${{ steps.tag-version.outputs.TAG_VERSION }}.nupkg

IntelliTect.TestTools.TestFramework.Tests/TestCaseTests/TestFailureTests.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,18 @@ public async Task DependencyWithMissingDependencyThrowsOriginalError()
4141
Assert.IsType<InvalidOperationException>(ex.InnerException);
4242
Assert.Contains("oops", ex.InnerException!.Message, StringComparison.InvariantCultureIgnoreCase);
4343
}
44+
45+
[Fact]
46+
public async Task AsyncBlockThrowsProperlyCatchAndLogException()
47+
{
48+
TestCase tc = new TestBuilder()
49+
.AddAsyncTestBlock<AsyncError>()
50+
.Build();
51+
52+
var ex = await Assert.ThrowsAsync<TestCaseException>(() => tc.ExecuteAsync());
53+
Assert.False(tc.Passed);
54+
var invalidOp = Assert.IsType<InvalidOperationException>(ex.InnerException);
55+
Assert.Contains("oops", invalidOp.Message, StringComparison.InvariantCultureIgnoreCase);
56+
}
4457
}
4558
}

IntelliTect.TestTools.TestFramework.Tests/TestData/TestBlocks/SingleDependencyBlocks.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using IntelliTect.TestTools.TestFramework.Tests.TestData.Dependencies;
22
using System;
3+
using System.Threading.Tasks;
34
using Xunit;
45

56
namespace IntelliTect.TestTools.TestFramework.Tests.TestData.TestBlocks
@@ -70,4 +71,13 @@ public bool Execute(SomeDependency dep)
7071
return true;
7172
}
7273
}
74+
75+
public class AsyncError : TestBlock
76+
{
77+
public async Task Execute()
78+
{
79+
await Task.Delay(1);
80+
throw new InvalidOperationException("Oops");
81+
}
82+
}
7383
}

IntelliTect.TestTools.TestFramework/TestCase.cs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,9 @@ public async Task ExecuteAsync()
9494
bool runSuccess = await TryRunBlock(tb, testBlockInstance, executeArgs);
9595
if (!runSuccess)
9696
{
97-
if (TestBlockException is null)
98-
{
99-
TestBlockException = new(
97+
TestBlockException ??= new(
10098
$"Unknown error occurred while running test block {tb}. " +
10199
"Please file an issue: https://github.com/IntelliTect/TestTools.TestFramework/issues");
102-
}
103100
break;
104101
}
105102
}
@@ -122,6 +119,10 @@ public async Task ExecuteAsync()
122119

123120
if (TestBlockException is null)
124121
{
122+
// Note: This likely needs to be moved up above the finally blocks.
123+
// If a test case "passes" i.e. finishes all of its test blocks, we probably need to know that
124+
// in the finally blocks.
125+
// Need to think about how to handle "passed" state if a finally block fails.
125126
Passed = true;
126127
Log?.Info("Test case finished successfully.");
127128
}
@@ -405,17 +406,17 @@ private async Task<bool> TryRunBlock(Block block, object blockInstance, List<obj
405406
() => FinallyBlockExceptions.Add(ex.InnerException)
406407
);
407408
}
408-
catch (ArgumentException ex)
409+
catch (TargetParameterCountException ex)
409410
{
411+
ex.Data.Add("AdditionalInfo", "Test block failed: Mismatched count between Execute method arguments and supplied dependencies.");
410412
HandleFinallyBlock(
411413
block,
412414
() => TestBlockException = ex,
413415
() => FinallyBlockExceptions.Add(ex)
414416
);
415417
}
416-
catch (TargetParameterCountException ex)
418+
catch (Exception ex)
417419
{
418-
ex.Data.Add("AdditionalInfo", "Test block failed: Mismatched count between Execute method arguments and supplied dependencies.");
419420
HandleFinallyBlock(
420421
block,
421422
() => TestBlockException = ex,

0 commit comments

Comments
 (0)