2
// ExternalTestRunner.cs
7
// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
9
// Permission is hereby granted, free of charge, to any person obtaining
10
// a copy of this software and associated documentation files (the
11
// "Software"), to deal in the Software without restriction, including
12
// without limitation the rights to use, copy, modify, merge, publish,
13
// distribute, sublicense, and/or sell copies of the Software, and to
14
// permit persons to whom the Software is furnished to do so, subject to
15
// the following conditions:
17
// The above copyright notice and this permission notice shall be
18
// included in all copies or substantial portions of the Software.
20
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31
using System.Reflection;
33
using System.Collections;
34
using System.Collections.Generic;
35
using System.Threading;
38
using NUnit.Framework;
39
using NUnit.Core.Filters;
41
namespace MonoDevelop.NUnit.External
43
public class NUnitTestRunner: MarshalByRefObject
45
public void Initialize (string nunitPath, string nunitCorePath)
47
// In some cases MS.NET can't properly resolve assemblies even if they
48
// are already loaded. For example, when deserializing objects from remoting.
49
AppDomain.CurrentDomain.AssemblyResolve += delegate (object s, ResolveEventArgs args) {
50
foreach (Assembly am in AppDomain.CurrentDomain.GetAssemblies ()) {
51
if (am.GetName ().FullName == args.Name)
57
// Force the loading of the NUnit.Framework assembly.
58
// It's needed since that dll is not located in the test dll directory.
59
Assembly.LoadFrom (nunitCorePath);
60
Assembly.LoadFrom (nunitPath);
62
// Initialize ExtensionHost if not already done
63
if ( !CoreExtensions.Host.Initialized )
64
CoreExtensions.Host.InitializeService();
67
public TestResult Run (EventListener listener, ITestFilter filter, string path, string suiteName, List<string> supportAssemblies)
69
InitSupportAssemblies (supportAssemblies);
72
filter = TestFilter.Empty;
74
RemoteTestRunner tr = new RemoteTestRunner ();
75
TestPackage package = new TestPackage (path);
76
if (!string.IsNullOrEmpty (suiteName))
77
package.TestName = suiteName;
79
return tr.Run (listener, filter);
82
public NunitTestInfo GetTestInfo (string path, List<string> supportAssemblies)
84
InitSupportAssemblies (supportAssemblies);
86
TestSuite rootTS = new TestSuiteBuilder ().Build (new TestPackage (path));
87
return BuildTestInfo (rootTS);
90
NunitTestInfo BuildTestInfo (Test test)
92
NunitTestInfo ti = new NunitTestInfo ();
94
// The name of inherited tests include the base class name as prefix.
95
// That prefix has to be removed
96
string tname = test.TestName.Name;
97
int i = tname.LastIndexOf ('.');
99
tname = tname.Substring (i + 1);
103
// Trim short name from end of full name to get the path
104
string testNameWithDelimiter = "." + tname;
105
if (test.TestName.FullName.EndsWith (testNameWithDelimiter)) {
106
int pathLength = test.TestName.FullName.Length - testNameWithDelimiter.Length;
107
ti.PathName = test.TestName.FullName.Substring(0, pathLength );
112
if (test.Tests != null && test.Tests.Count > 0) {
113
ti.Tests = new NunitTestInfo [test.Tests.Count];
114
for (int n=0; n<test.Tests.Count; n++)
115
ti.Tests [n] = BuildTestInfo ((Test)test.Tests [n]);
120
void InitSupportAssemblies (List<string> supportAssemblies)
122
// Preload support assemblies (they may not be in the test assembly directory nor in the gac)
123
foreach (string asm in supportAssemblies)
124
Assembly.LoadFrom (asm);
127
public override object InitializeLifetimeService ()
135
public class NunitTestInfo
138
public string PathName;
139
public NunitTestInfo[] Tests;
143
public class TestNameFilter: ITestFilter
147
public TestNameFilter (string name)
152
#region ITestFilter implementation
154
public bool Pass (ITest test)
156
if ((test is global::NUnit.Core.TestCase) && test.TestName.FullName == name)
158
if (test.Tests != null) {
159
foreach (ITest ct in test.Tests) {
167
public bool Match (ITest test)
172
public bool IsEmpty {