1

I have a .NET project with 2000 unit tests written in NUnit, that I would like to migrate to Mono.

The project is recompiled using Mono 3.0.2/MonoDevelop 3.0.5 on Mac OS X. I am able to run all unit tests using the integrated test runner of MonoDevelop.

However, I have a lot of tests marked "LongRunning" using TestCaseAttribute:

[TestCase(1, Category="LongRunning")]

but I couldn't exclude them using Unit Test Options (from menu View -> Pads -> Unit Tests -> ...).

enter image description here

Including/excluding categories options are there but trying them has no effect.

How do I exclude LongRunning unit tests using MonoDevelop test runner?

pad
  • 41,040
  • 7
  • 92
  • 166
  • +1 because I didn't know about this option. But it doesn't work here either (on linux). I suspect a bug. If I add that filter then close and reopen the solution, the value I entered is forgotten. – Jester Jan 18 '13 at 16:11
  • @Jester: Thanks for your info. If I couldn't find a solution (or workaround) soon, I probably have to submit a bug report to Xamarin. – pad Jan 18 '13 at 18:42

1 Answers1

1

Okay, the two problems are separate. This patch should fix your problem:

diff --git a/main/src/addins/NUnit/Services/NUnitAssemblyTestSuite.cs b/main/src/addins/NUnit/Services/NUnitAssemblyTestSuite.cs
index 385e50f..b2addd6 100644
--- a/main/src/addins/NUnit/Services/NUnitAssemblyTestSuite.cs
+++ b/main/src/addins/NUnit/Services/NUnitAssemblyTestSuite.cs
@@ -357,19 +357,19 @@ namespace MonoDevelop.NUnit
                        ITestFilter filter = null;
                        if (test != null) {
                                if (test is UnitTestGroup) {
-                                       filter = new TestNameFilter (CollectTests ((UnitTestGroup)test));
+                                       NUnitCategoryOptions categoryOptions = (NUnitCategoryOptions) test.GetOptions (typeof(NUnitCategoryOptions));
+                                       if (categoryOptions != null && categoryOptions.EnableFilter && categoryOptions.Categories.Count > 0) {
+                                               string[] cats = new string [categoryOptions.Categories.Count];
+                                               categoryOptions.Categories.CopyTo (cats, 0);
+                                               filter = new CategoryFilter (cats);
+                                               if (categoryOptions.Exclude)
+                                                       filter = new NotFilter (filter);
+                                       } else {
+                                               filter = new TestNameFilter (CollectTests ((UnitTestGroup)test));
+                                       }
                                } else {
                                        filter = new TestNameFilter (test.TestId);
                                }
-                       } else {
-                               NUnitCategoryOptions categoryOptions = (NUnitCategoryOptions) test.GetOptions (typeof(NUnitCategoryOptions));
-                               if (categoryOptions.EnableFilter && categoryOptions.Categories.Count > 0) {
-                                       string[] cats = new string [categoryOptions.Categories.Count];
-                                       categoryOptions.Categories.CopyTo (cats, 0);
-                                       filter = new CategoryFilter (cats);
-                                       if (categoryOptions.Exclude)
-                                               filter = new NotFilter (filter);
-                               }
                        }

                        RunData rd = new RunData ();

I also have a patch for the other problem (settings not being written) but even though it doesn't touch serialization code, MD can not read back the properties it saves. I am looking into that.

Jester
  • 56,577
  • 4
  • 81
  • 125
  • +1 for willing to help. Any idea how I should apply the fix? I use binary distribution of MonoDevelop. Maybe recompile NUNit add-in from source and re-add it to MonoDevelop? Once you solve the problem with written settings, please submit a pull request to MonoDevelop on Github. I think many others will benefit from your help. – pad Jan 20 '13 at 08:31
  • I have [uploaded a binary version](http://www.sendspace.com/file/fhi5u9), no guarantees that it's compatible with your MD. – Jester Jan 20 '13 at 13:45
  • No, it isn't. When I start MonoDevelop, there is an error message complaining that `MonoDevelop.NUnit.dll` has the wrong public key. – pad Jan 20 '13 at 18:37
  • The bug is reopened https://bugzilla.xamarin.com/show_bug.cgi?id=9680 . It seems not to be fixed soon, sigh. – pad Feb 15 '13 at 12:02
  • Yeah I must have messed something up with the patch, although I did check single tests were working here. Going to look at it again. – Jester Feb 15 '13 at 12:08
  • Thanks again. I'm looking forward to a fix. – pad Feb 15 '13 at 12:13