Skip to content

Commit 32d9484

Browse files
pjcollinsjonpryor
authored andcommitted
[tests] Category support in TestRunner.NUnit (#1963)
Context: #1534 The `DotNetInterfacesShouldEqualJavaInterfaces()` unit test *occasionally* fails on certain Android devices, such as: * [Oneplus One](https://gist.github.com/pjcollins/50b3036dd4a0b4a4d881a24fe49ab30d): 09-25 12:36:18.234 I/mono-stdout(26038): [FAIL] : #6.3 (dummy0 not found in Java interfaces) * [Samsung S8](https://gist.github.com/pjcollins/5782e1bc225cdf105a75491e23f257d6) 09-29 10:26:41.754 I/mono-stdout(18006): Expected: 19 09-29 10:26:41.754 I/mono-stdout(18006): But was: 5 * [Nexus 6p (API 25)](https://gist.github.com/pjcollins/062f2124e1e76561809193450f97e768) 09-29 10:26:05.053 I/mono-stdout(32432): Expected: 22 09-29 10:26:05.053 I/mono-stdout(32432): But was: 4 We do not yet understand what is causing these failures. That said, QA doesn't want to continue seeing these errors in QA builds, as reviewing "errors for which we've already filed bugs" is tedious and annoying, and makes it easier to overlook new issues. Extend the `[CategoryAttribute]` support in 096210c so that the new `TestRunner.NUnit` test runner (c4e8165) can also use the same `$(ExcludeCategories)` MSBuild property to cause tests to be skipped. Add `[Category("NetworkInterfaces")]` to the `DotNetInterfacesShouldEqualJavaInterfaces()` test. Together, these two changes will allow QA to selectively skip the `DotNetInterfacesShouldEqualJavaInterfaces()` test.
1 parent 306d119 commit 32d9484

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

src/Mono.Android/Test/System.Net/NetworkInterfaces.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ bool HardwareAddressesAreEqual (byte[] one, byte[] two)
100100
}
101101
}
102102

103-
[Test]
103+
[Test, Category("NetworkInterfaces")]
104104
public void DotNetInterfacesShouldEqualJavaInterfaces ()
105105
{
106106
List <InterfaceInfo> dotnetInterfaces = GetInfos (MNetworkInterface.GetAllNetworkInterfaces ());

tests/TestRunner.Core/TestInstrumentation.cs

+11
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,17 @@ protected virtual Assembly LoadTestAssembly (string filePath)
315315
return Assembly.LoadFrom (filePath);
316316
}
317317

318+
protected Dictionary<string, string> GetStringExtrasFromBundle ()
319+
{
320+
var filtersFromBundle = new Dictionary<string, string> ();
321+
foreach (var key in arguments.KeySet ()) {
322+
string value = arguments.GetString (key);
323+
if (!string.IsNullOrEmpty (value))
324+
filtersFromBundle.Add (key, value);
325+
}
326+
return filtersFromBundle;
327+
}
328+
318329
protected virtual void ConfigureFilters (TRunner runner)
319330
{}
320331

tests/TestRunner.NUnit/NUnitTestInstrumentation.cs

+17
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,17 @@ protected override NUnitTestRunner CreateRunner (LogWriter logger, Bundle bundle
4242
};
4343
}
4444

45+
IEnumerable<string> GetFilterValuesFromExtras (string key)
46+
{
47+
Dictionary<string, string> extras = GetStringExtrasFromBundle ();
48+
if (extras.ContainsKey (key)) {
49+
string filterValue = extras [key];
50+
if (!string.IsNullOrEmpty (filterValue))
51+
return filterValue.Split (':');
52+
}
53+
return null;
54+
}
55+
4556
protected override void ConfigureFilters (NUnitTestRunner runner)
4657
{
4758
base.ConfigureFilters(runner);
@@ -54,9 +65,15 @@ protected override void ConfigureFilters (NUnitTestRunner runner)
5465
Log.Info (LogTag, "Configuring test categories to include:");
5566
ChainCategoryFilter (IncludedCategories, false, ref filter);
5667

68+
Log.Info (LogTag, "Configuring test categories to include from extras:");
69+
ChainCategoryFilter (GetFilterValuesFromExtras ("include"), false, ref filter);
70+
5771
Log.Info (LogTag, "Configuring test categories to exclude:");
5872
ChainCategoryFilter (ExcludedCategories, true, ref filter);
5973

74+
Log.Info(LogTag, "Configuring test categories to exclude from extras:");
75+
ChainCategoryFilter (GetFilterValuesFromExtras ("exclude"), true, ref filter);
76+
6077
Log.Info (LogTag, "Configuring tests to exclude (by name):");
6178
ChainTestNameFilter (ExcludedTestNames?.ToArray (), ref filter);
6279

0 commit comments

Comments
 (0)