Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[UWP] Remove image comparison from unit tests #3724

Merged
merged 2 commits into from
Jan 13, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
[UWP] Remove image comparison from unit tests
  • Loading branch information
Rebecca Muraira committed Jan 13, 2020
commit 57eb1a1b5d047281148a3cba7c11ba0ab11c5140
13 changes: 12 additions & 1 deletion source/uwp/UWPTestLibrary/TestResultViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,8 @@ public TestStatus Status
}
}

answer.Status.Error = answer.TestResult.Error;

// If both had error, compare via the error
if (answer.ExpectedError != null && answer.TestResult.Error != null)
{
Expand Down Expand Up @@ -463,6 +465,8 @@ public class TestStatus
/// <summary> This is a new card</summary>
public bool NewCard { get; set; } = false;

public string Error;

/// <summary> Set the status to a passing result</summary>
public void SetToPassingStatus(bool matchedViaError)
{
Expand All @@ -488,7 +492,14 @@ public override string ToString()
}
else if (NewCard == true)
Copy link
Member

@paulcam206 paulcam206 Jan 13, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
else if (NewCard == true)
else if (NewCard)

not your bug, but... :) #Resolved

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably is my bug, to be honest :)

Fixed.


In reply to: 366065171 [](ancestors = 366065171)

{
return "New Card Added";
if (Error == null)
{
return "New Card Added";
}
else
{
return "Error in new card";
}
}
else if (!OriginalMatched && ((!ImageMatched || !JsonRoundTripMatched) && !MatchedViaError))
{
Expand Down
94 changes: 40 additions & 54 deletions source/uwp/UWPUnitTests/UnitTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,72 +113,58 @@ public async Task TestCardInDispatcher(FileViewModel hostConfig, FileViewModel c

async public Task TestCard(FileViewModel hostConfigFile, FileViewModel cardFile)
{
uint reruns = 0;
TestResultViewModel result = null;
bool retryImage = true;
bool testPass = false;
var renderResult = await UWPTestLibrary.RenderTestHelpers.RenderCard(cardFile, hostConfigFile);

while (retryImage)
if (renderResult.Tree != null)
{
var renderResult = await UWPTestLibrary.RenderTestHelpers.RenderCard(cardFile, hostConfigFile);
UWPTestLibrary.ImageWaiter imageWaiter = new ImageWaiter(renderResult.Tree);

if (renderResult.Tree != null)
{
UWPTestLibrary.ImageWaiter imageWaiter = new ImageWaiter(renderResult.Tree);

StackPanel stackPanel = new StackPanel();
stackPanel.Children.Add(renderResult.Tree);

Border border = new Border();
border.Width = renderResult.CardWidth;
border.Child = stackPanel;

ScrollViewer scrollViewer = new ScrollViewer();
scrollViewer.Content = border;
StackPanel stackPanel = new StackPanel();
stackPanel.Children.Add(renderResult.Tree);

(Window.Current.Content as Frame).Content = scrollViewer;
Border border = new Border();
border.Width = renderResult.CardWidth;
border.Child = stackPanel;

await imageWaiter.WaitOnAllImagesAsync();

}

StorageFile imageResultFile = null;
StorageFile jsonResultFile = null;
if (renderResult.Error == null)
{
imageResultFile = await _tempResultsFolder.CreateFileAsync("Result.png", CreationCollisionOption.GenerateUniqueName);
jsonResultFile = await _tempResultsFolder.CreateFileAsync("Result.json", CreationCollisionOption.GenerateUniqueName);
ScrollViewer scrollViewer = new ScrollViewer();
scrollViewer.Content = border;

await UWPTestLibrary.RenderTestHelpers.ResultsToFile(imageResultFile, jsonResultFile, renderResult.RoundTrippedJSON, renderResult.Tree);
}
(Window.Current.Content as Frame).Content = scrollViewer;

await Task.Delay(10);
await imageWaiter.WaitOnAllImagesAsync();

result = await TestResultViewModel.CreateAsync(
cardFile: cardFile,
hostConfigFile: hostConfigFile,
renderedTestResult: renderResult,
actualImageFile: imageResultFile,
actualJsonFile: jsonResultFile,
expectedFolder: _expectedFolder,
sourceHostConfigsFolder: _sourceHostConfigsFolder,
sourceCardsFolder: _sourceCardsFolder);
}

testPass = result.Status.IsPassingStatus() && result.Status.OriginalMatched;
StorageFile imageResultFile = null;
StorageFile jsonResultFile = null;
if (renderResult.Error == null)
{
imageResultFile = await _tempResultsFolder.CreateFileAsync("Result.png", CreationCollisionOption.GenerateUniqueName);
jsonResultFile = await _tempResultsFolder.CreateFileAsync("Result.json", CreationCollisionOption.GenerateUniqueName);

if(!testPass)
{
// Retry if we failed on image matching for an unchanged card to allow for
// occasional differences in image rendering
retryImage = result.Status.OriginalMatched && !result.Status.ImageMatched && (reruns < 3);
reruns++;
}
else
{
retryImage = false;
}
await UWPTestLibrary.RenderTestHelpers.ResultsToFile(imageResultFile, jsonResultFile, renderResult.RoundTrippedJSON, renderResult.Tree);
}

await Task.Delay(10);

TestResultViewModel result = await TestResultViewModel.CreateAsync(
cardFile: cardFile,
hostConfigFile: hostConfigFile,
renderedTestResult: renderResult,
actualImageFile: imageResultFile,
actualJsonFile: jsonResultFile,
expectedFolder: _expectedFolder,
sourceHostConfigsFolder: _sourceHostConfigsFolder,
sourceCardsFolder: _sourceCardsFolder);

// For the unit test, only check that the renderer succeeded (or not) as expected, and that the round tripped json is unchanged.
// Image comparison for the time being is not quite stable enough to run as a unit test.
// Allow new cards to pass as long as they don't have an error
bool testPass =
result.Status.MatchedViaError ||
result.Status.JsonRoundTripMatched ||
(result.Status.NewCard && (result.Status.Error == null));

if (!testPass)
{
throw new Exception(result.Status.ToString() + ": " + result.HostConfigName + "\\" + result.CardName);
Expand Down