~nunit-vs-team/nunit-vs-adapter/trunk

« back to all changes in this revision

Viewing changes to src/NUnitTestAdapter/NUnitTestDiscoverer.cs

  • Committer: Charlie Poole
  • Date: 2013-08-14 22:36:58 UTC
  • Revision ID: charlie@nunit.org-20130814223658-lz1y2mmvgy6tfhwg
Change AssemblyFilter to AssemblyRunner and give it responsibility for running tests in each assembly. Eliminate caching of nunit tests. Ensure VS tests are initially cached so that the NUnitEventListener always has access to them. Add some tests. General cleanup.

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
 
23
23
        #region ITestDiscoverer Members
24
24
 
25
 
        public void DiscoverTests(IEnumerable<string> sources, IDiscoveryContext discoveryContext, IMessageLogger logger, ITestCaseDiscoverySink discoverySink)
 
25
        public void DiscoverTests(IEnumerable<string> sources, IDiscoveryContext discoveryContext, IMessageLogger messageLogger, ITestCaseDiscoverySink discoverySink)
26
26
        {
27
 
            // Set the logger to use for messages
28
 
            Logger = logger;
 
27
            testLog.Initialize(messageLogger);
29
28
            Info("discovering tests", "started");
30
29
            
31
30
            // Ensure any channels registered by other adapters are unregistered
33
32
 
34
33
            foreach (string sourceAssembly in sources)
35
34
            {
36
 
#if DEBUG
37
 
                SendInformationalMessage("Processing " + sourceAssembly);
38
 
#endif
 
35
                testLog.SendDebugMessage("Processing " + sourceAssembly);
 
36
 
39
37
                TestRunner runner = new TestDomain();
40
38
                TestPackage package = new TestPackage(sourceAssembly);
41
39
 
43
41
                {
44
42
                    if (runner.Load(package))
45
43
                    {
46
 
                        this.testConverter = new TestConverter(sourceAssembly);
 
44
                        this.testConverter = new TestConverter(testLog, sourceAssembly);
47
45
 
48
46
                        int cases = ProcessTestCases(runner.Test, discoverySink);
49
 
#if DEBUG
50
 
                        SendInformationalMessage(string.Format("Discovered {0} test cases", cases));
51
 
#endif
 
47
 
 
48
                        testLog.SendDebugMessage(string.Format("Discovered {0} test cases", cases));
52
49
                    }
53
50
                    else
54
51
                    {
55
 
                        NUnitLoadError(sourceAssembly);
 
52
                        testLog.NUnitLoadError(sourceAssembly);
56
53
                    }
57
54
                }
58
55
                catch (System.BadImageFormatException)
59
56
                {
60
57
                    // we skip the native c++ binaries that we don't support.
61
 
                    AssemblyNotSupportedWarning(sourceAssembly);
 
58
                    testLog.AssemblyNotSupportedWarning(sourceAssembly);
62
59
                }
63
60
 
64
61
                catch (System.IO.FileNotFoundException ex)
65
62
                {
66
63
                    // Probably from the GetExportedTypes in NUnit.core, attempting to find an assembly, not a problem if it is not NUnit here
67
 
                    DependentAssemblyNotFoundWarning(ex.FileName, sourceAssembly);
 
64
                    testLog.DependentAssemblyNotFoundWarning(ex.FileName, sourceAssembly);
68
65
                }
69
66
                catch (System.Exception ex)
70
67
                {
71
 
                    SendErrorMessage("Exception thrown discovering tests in " + sourceAssembly, ex);
 
68
                    testLog.SendErrorMessage("Exception thrown discovering tests in " + sourceAssembly, ex);
72
69
                }
73
70
                finally
74
71
                {
75
 
                    if (testConverter!=null)
76
 
                        testConverter.Dispose();
77
72
                    runner.Unload();
78
73
                }
79
74
            }
 
75
 
80
76
            Info("discovering test","finished");
81
77
        }
82
78
 
103
99
                }
104
100
                catch (System.Exception ex)
105
101
                {
106
 
                    SendErrorMessage("Exception converting " + test.TestName.FullName, ex);
 
102
                    testLog.SendErrorMessage("Exception converting " + test.TestName.FullName, ex);
107
103
                }
108
104
            }
109
105