Skip to content

Commit b8b12c4

Browse files
committed
Only invalidate test results if the code of the unit test has changed. Closes #4705
1 parent b1b97b2 commit b8b12c4

File tree

4 files changed

+30
-18
lines changed

4 files changed

+30
-18
lines changed

Rubberduck.Core/UI/UnitTesting/TestExplorerModel.cs

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,16 @@ internal class TestExplorerModel : ViewModelBase, IDisposable
1313
{
1414
private readonly IVBE _vbe;
1515
private readonly Dispatcher _dispatcher;
16-
private readonly ITestEngine testEngine;
16+
private readonly ITestEngine _testEngine;
1717

1818
public TestExplorerModel(IVBE vbe, ITestEngine testEngine)
1919
{
2020
_vbe = vbe;
21-
this.testEngine = testEngine;
21+
_testEngine = testEngine;
2222

23-
testEngine.TestsRefreshed += HandleTestsRefreshed;
24-
testEngine.TestRunCompleted += HandleRunCompletion;
25-
testEngine.TestCompleted += HandleTestCompletion;
23+
_testEngine.TestsRefreshed += HandleTestsRefreshed;
24+
_testEngine.TestRunCompleted += HandleRunCompletion;
25+
_testEngine.TestCompleted += HandleTestCompletion;
2626
_dispatcher = Dispatcher.CurrentDispatcher;
2727
}
2828

@@ -52,17 +52,25 @@ private void HandleTestCompletion(object sender, TestCompletedEventArgs e)
5252

5353
private void HandleTestsRefreshed(object sender, EventArgs args)
5454
{
55+
var previous = Tests.ToList();
56+
5557
Tests.Clear();
56-
foreach (var test in testEngine.Tests.Select(test => new TestMethodViewModel(test)))
58+
foreach (var test in _testEngine.Tests)
5759
{
58-
Tests.Add(test);
60+
var adding = new TestMethodViewModel(test);
61+
var match = previous.FirstOrDefault(ut => ut.Method.Equals(test));
62+
if (match != null)
63+
{
64+
adding.Result = match.Result;
65+
}
66+
Tests.Add(adding);
5967
}
6068
RefreshProgressBarColor();
6169
}
6270

6371
private void RefreshProgressBarColor()
6472
{
65-
var overallOutcome = testEngine.CurrentAggregateOutcome;
73+
var overallOutcome = _testEngine.CurrentAggregateOutcome;
6674
switch (overallOutcome)
6775
{
6876
case TestOutcome.Failed:
@@ -85,7 +93,8 @@ private void RefreshProgressBarColor()
8593
private long _totalDuration;
8694
public long TotalDuration
8795
{
88-
get { return _totalDuration; } private set
96+
get => _totalDuration;
97+
private set
8998
{
9099
_totalDuration = value;
91100
OnPropertyChanged();
@@ -127,11 +136,11 @@ public bool IsBusy
127136

128137
public void Dispose()
129138
{
130-
if (testEngine != null)
139+
if (_testEngine != null)
131140
{
132-
testEngine.TestCompleted -= HandleTestCompletion;
133-
testEngine.TestsRefreshed -= HandleTestsRefreshed;
134-
testEngine.TestRunCompleted -= HandleRunCompletion;
141+
_testEngine.TestCompleted -= HandleTestCompletion;
142+
_testEngine.TestsRefreshed -= HandleTestsRefreshed;
143+
_testEngine.TestRunCompleted -= HandleRunCompletion;
135144
}
136145
}
137146
}

Rubberduck.Core/UI/UnitTesting/TestExplorerViewModel.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ private void TestEngineTestCompleted(object sender, TestCompletedEventArgs e)
8282
{
8383
// Propagate the event
8484
TestCompleted?.Invoke(sender, e);
85+
Tests.Refresh();
8586
}
8687

8788
public INavigateSource SelectedItem => SelectedTest;

Rubberduck.Core/UI/UnitTesting/ViewModels/TestMethodViewModel.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using Rubberduck.Interaction.Navigation;
22
using Rubberduck.UnitTesting;
33
using Rubberduck.VBEditor;
4-
using System.Collections.Generic;
54

65
namespace Rubberduck.UI.UnitTesting.ViewModels
76
{
@@ -12,7 +11,7 @@ public TestMethodViewModel(TestMethod test)
1211
Method = test;
1312
}
1413

15-
public TestMethod Method { get; private set; }
14+
public TestMethod Method { get; }
1615

1716
private TestResult _result = new TestResult(TestOutcome.Unknown);
1817

Rubberduck.UnitTesting/UnitTesting/TestMethod.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System;
2-
using System.Diagnostics.CodeAnalysis;
32
using System.Linq;
43
using Rubberduck.Parsing;
54
using Rubberduck.Parsing.Annotations;
@@ -10,15 +9,17 @@
109

1110
namespace Rubberduck.UnitTesting
1211
{
13-
[SuppressMessage("ReSharper", "ExplicitCallerInfoArgument")]
1412
public class TestMethod : IEquatable<TestMethod>, INavigateSource
1513
{
1614
public TestMethod(Declaration declaration)
1715
{
1816
Declaration = declaration;
17+
TestCode = declaration.Context.GetText();
1918
}
2019
public Declaration Declaration { get; }
2120

21+
public string TestCode { get; }
22+
2223
public TestCategory Category
2324
{
2425
get
@@ -36,8 +37,10 @@ public NavigateCodeEventArgs GetNavigationArgs()
3637
return new NavigateCodeEventArgs(new QualifiedSelection(Declaration.QualifiedName.QualifiedModuleName, Declaration.Context.GetSelection()));
3738
}
3839

39-
public bool Equals(TestMethod other) => other != null && Declaration.QualifiedName.Equals(other.Declaration.QualifiedName);
40+
public bool Equals(TestMethod other) => other != null && Declaration.QualifiedName.Equals(other.Declaration.QualifiedName) && TestCode.Equals(other.TestCode);
41+
4042
public override bool Equals(object obj) => obj is TestMethod method && Equals(method);
43+
4144
public override int GetHashCode() => Declaration.QualifiedName.GetHashCode();
4245
}
4346
}

0 commit comments

Comments
 (0)