Skip to content

Commit

Permalink
Test - Output QUnit results if tests failed
Browse files Browse the repository at this point in the history
  • Loading branch information
amaitland committed Oct 14, 2021
1 parent db9e041 commit 1a85419
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 9 deletions.
26 changes: 20 additions & 6 deletions CefSharp.Test/JavascriptBinding/IntegrationTestFacts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,18 @@ public async Task LoadJavaScriptBindingQunitTestsSuccessfulCompletion()
repo.Register("boundAsync2", new AsyncBoundObject(), isAsync: true, options: bindingOptions);

browser.CreateBrowser();
var success = await browser.WaitForQUnitTestExeuctionToComplete();
var response = await browser.WaitForQUnitTestExeuctionToComplete();

Assert.True(success);
if (!response.Success)
{
output.WriteLine("QUnit Details : {0}", response.Details);
output.WriteLine("QUnit Passed : {0}", response.Total);
output.WriteLine("QUnit Total : {0}", response.Passed);
}

output.WriteLine("QUnit Tests result: {0}", success);
Assert.True(response.Success);

output.WriteLine("QUnit Tests result: {0}", response.Success);
}
}

Expand All @@ -92,11 +99,18 @@ public async Task LoadLegacyJavaScriptBindingQunitTestsSuccessfulCompletion()
repo.Register("boundAsync", new AsyncBoundObject(), isAsync: true, options: bindingOptions);

browser.CreateBrowser();
var success = await browser.WaitForQUnitTestExeuctionToComplete();
var response = await browser.WaitForQUnitTestExeuctionToComplete();

Assert.True(success);
if(!response.Success)
{
output.WriteLine("QUnit Details : {0}", response.Details);
output.WriteLine("QUnit Passed : {0}", response.Total);
output.WriteLine("QUnit Total : {0}", response.Passed);
}

output.WriteLine("QUnit Tests result: {0}", success);
Assert.True(response.Success);

output.WriteLine("QUnit Tests result: {0}", response.Success);
}
}
#endif
Expand Down
19 changes: 19 additions & 0 deletions CefSharp.Test/QUnitTestResult.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright © 2021 The CefSharp Authors. All rights reserved.
//
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.

namespace CefSharp.Test
{
public class QUnitTestResult
{
public bool Success
{
get { return Passed == Total; }
}

public int Passed { get; set; }
public int Total { get; set; }

public string Details { get; set; }
}
}
6 changes: 3 additions & 3 deletions CefSharp.Test/WebBrowserTestExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,11 @@ public static Task<LoadUrlAsyncResponse> LoadRequestAsync(this IWebBrowser brows
return tcs.Task;
}

public static Task<bool> WaitForQUnitTestExeuctionToComplete(this IWebBrowser browser)
public static Task<QUnitTestResult> WaitForQUnitTestExeuctionToComplete(this IWebBrowser browser)
{
//If using .Net 4.6 then use TaskCreationOptions.RunContinuationsAsynchronously
//and switch to tcs.TrySetResult below - no need for the custom extension method
var tcs = new TaskCompletionSource<bool>(TaskCreationOptions.RunContinuationsAsynchronously);
var tcs = new TaskCompletionSource<QUnitTestResult>(TaskCreationOptions.RunContinuationsAsynchronously);

EventHandler<JavascriptMessageReceivedEventArgs> handler = null;
handler = (sender, args) =>
Expand All @@ -95,7 +95,7 @@ public static Task<bool> WaitForQUnitTestExeuctionToComplete(this IWebBrowser br
var total = (int)details.total;
var passed = (int)details.passed;
tcs.TrySetResult(total == passed);
tcs.TrySetResult(new QUnitTestResult { Details = details, Passed = passed, Total = total });
}
else
{
Expand Down

0 comments on commit 1a85419

Please sign in to comment.