Skip to content

Commit

Permalink
[TouchRunner] Keep track of the last shown test suite, and return to …
Browse files Browse the repository at this point in the history
…it when the app is relaunched. (#74)
  • Loading branch information
rolfbjarne committed Jul 14, 2020
1 parent 857c584 commit 74fbc3f
Showing 1 changed file with 59 additions and 3 deletions.
62 changes: 59 additions & 3 deletions NUnitLite/TouchRunner/TouchRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,53 @@ public void LoadSync ()
assemblies.Clear ();
}

public void SelectLastTestSuite ()
{
var lastSuite = NSUserDefaults.StandardUserDefaults.StringForKey ("CurrentTest");

if (string.IsNullOrEmpty (lastSuite))
return;

var hierarchy = new List<ITest> ();
var test = Find (suite, lastSuite, hierarchy);
if (hierarchy.Count < 2)
return;
// Remove the last one, that's the main test suite
hierarchy.RemoveAt (hierarchy.Count - 1);
for (var i = hierarchy.Count - 1; i >= 0; i--) {
if (hierarchy [i] is TestSuite ts) {
Show (ts);
} else {
break;
}
}
}

ITest Find (ITest parent, string fullname, List<ITest> hierarchy)
{
if (parent.FullName == fullname) {
hierarchy.Add (parent);
return parent;
}

foreach (var test in parent.Tests) {
var rv = Find (test, fullname, hierarchy);
if (rv != null) {
hierarchy.Add (parent);
return test;
}
}

return null;
}


public void AutoRun ()
{
if (!AutoStart)
if (!AutoStart) {
SelectLastTestSuite ();
return;
}

ExecuteOnMainThread (() => {
Run ();
Expand Down Expand Up @@ -375,6 +418,10 @@ bool ShowConnectionErrorAlert (string hostname, int port, Exception ex)

protected abstract void WriteDeviceInformation (TextWriter writer);

public virtual void Show (TestSuite suite)
{
}

public void CloseWriter ()
{
int total = PassedCount + InconclusiveCount + FailedCount; // ignored are *not* run
Expand Down Expand Up @@ -559,6 +606,11 @@ public ITest LoadedTest {
}
}

public void NotifySelectedTest (ITest test)
{
NSUserDefaults.StandardUserDefaults.SetString (test.FullName, "CurrentTest");
}

public void TestOutput (TestOutput testOutput)
{
}
Expand Down Expand Up @@ -694,7 +746,7 @@ void Credits ()
Dictionary<TestSuite, TestSuiteElement> suite_elements = new Dictionary<TestSuite, TestSuiteElement> ();
Dictionary<TestMethod, TestCaseElement> case_elements = new Dictionary<TestMethod, TestCaseElement> ();

public void Show (TestSuite suite)
public override void Show (TestSuite suite)
{
NavigationController.PushViewController (suites_dvc [suite], true);
}
Expand Down Expand Up @@ -734,7 +786,11 @@ TestSuiteElement Setup (TestSuite suite)
};
root.Add (options);

suites_dvc.Add (suite, new TouchViewController (root));
var tvc = new TouchViewController (root);
tvc.ViewAppearing += (object sender, EventArgs ea) => {
NotifySelectedTest (suite);
};
suites_dvc.Add (suite, tvc);
return tse;
}

Expand Down

0 comments on commit 74fbc3f

Please sign in to comment.