Skip to content

Commit

Permalink
[TouchRunner] Only update the UI for a single test after the test has…
Browse files Browse the repository at this point in the history
… finished running. (#72)

Only update the UI for a single test after we're notified that the test has
finished running. This is a step towards making async tests work properly,
where we can't assume that the test has finished after calling Run.

Also we only want to show more details for a test if we ran that test as a
result of tapping on it.
  • Loading branch information
rolfbjarne committed Jul 14, 2020
1 parent ba93ddf commit 1a7068c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 19 deletions.
38 changes: 22 additions & 16 deletions NUnitLite/TouchRunner/TestCaseElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
namespace MonoTouch.NUnit.UI {

class TestCaseElement : TestElement {
bool tapped;

public TestCaseElement (TestMethod testCase, TouchRunner runner)
: base (testCase, runner)
Expand All @@ -59,21 +60,7 @@ public TestCaseElement (TestMethod testCase, TouchRunner runner)
#endif

Runner.CloseWriter ();
// display more details on (any) failure (but not when ignored)
if ((TestCase.RunState == RunState.Runnable) && !Result.IsSuccess ()) {
var root = new RootElement ("Results") {
new Section () {
new TestResultElement (Result)
}
};
var dvc = new DialogViewController (root, true) { Autorotate = true };
runner.NavigationController.PushViewController (dvc, true);
}
// we still need to update our current element
if (GetContainerTableView () != null) {
var root = GetImmediateRootElement ();
root.Reload (this, UITableViewRowAnimation.Fade);
}
tapped = true;
};
}

Expand All @@ -83,7 +70,7 @@ public TestMethod TestCase {

public void Run ()
{
Update (Runner.Run (TestCase));
Runner.Run (TestCase);
}

public override void Update ()
Expand All @@ -105,6 +92,25 @@ public override void Update ()
// Assert.Ignore falls into this
Value = Result.GetMessage ();
}

if (tapped) {
// display more details on (any) failure (but not when ignored)
if ((TestCase.RunState == RunState.Runnable) && !Result.IsSuccess ()) {
var root = new RootElement ("Results") {
new Section () {
new TestResultElement (Result)
}
};
var dvc = new DialogViewController (root, true) { Autorotate = true };
Runner.NavigationController.PushViewController (dvc, true);
}
// we still need to update our current element
if (GetContainerTableView () != null) {
var root = GetImmediateRootElement ();
root.Reload (this, UITableViewRowAnimation.Fade);
}
tapped = false;
}
}
}
}
2 changes: 1 addition & 1 deletion NUnitLite/TouchRunner/TestSuiteElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public TestSuite Suite {

public void Run ()
{
Result = Runner.Run (Suite);
Runner.Run (Suite);
}

public override void Update ()
Expand Down
3 changes: 1 addition & 2 deletions NUnitLite/TouchRunner/TouchRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ bool AddSuite (TestSuite ts)
return true;
}

public TestResult Run (Test test)
public void Run (Test test)
{
PassedCount = 0;
IgnoredCount = 0;
Expand Down Expand Up @@ -551,7 +551,6 @@ ITestResult find_result (ITestResult tr)
wi.Execute (current);
Result = wi.Result;
#endif
return Result;
}

public ITest LoadedTest {
Expand Down

0 comments on commit 1a7068c

Please sign in to comment.