Esempio n. 1
0
        public void TestDurationReported()
        {
            AssemblyFactory.Type = typeof(AssemblyMock);
            var remoteLoader = new RemoteLoader();
            var listener     = new MyTestListener();

            remoteLoader.Listener = listener;
            remoteLoader.LoadAssembly(new AssemblyName {
                CodeBase = _assemblyPathName
            });
            remoteLoader.RunTests(new TestRun(new AllTestsCriterion()), new StringWriter());
            Assert.Greater(listener.Duration, 0);
        }
            private TestResult RunTests(string assemblyPath)
            {
                AssemblyMetadata assemblyMetadata = AssemblyUtils.GetAssemblyMetadata(assemblyPath, AssemblyMetadataFields.Default);

                if (assemblyMetadata == null)
                {
                    ITestContext testContext = listOfTestCommands[0].StartPrimaryChildStep(topTestStep);
                    testContext.LifecyclePhase = LifecyclePhases.Execute;
                    testContext.LogWriter.Failures.WriteLine("Test assembly does not exist or is not a valid .Net assembly. [{0}]", assemblyPath ?? String.Empty);
                    return(testContext.FinishStep(TestOutcome.Error, null));
                }

                // Remark: We cannot use the RemoteLoader directly from this AppDomain.
                //   csUnit v2.5 contains a bug in its detection of the NUnitAdapter.  It tries
                //   to enumerate ALL types in ALL assemblies that are loaded in the AppDomain.
                //   Bad news for us because some of these types derived from other types in
                //   assemblies that cannot be loaded (eg. VisualStudio APIs).
                //   So csUnit promptly blows up.  The workaround is to create our own AppDomain.
                //   We cannot use the csUnit Loader because it does things like report
                //   events asynchronously and possibly out of order or even in parallel. -- Jeff.
                // See also: http://sourceforge.net/tracker/index.php?func=detail&aid=2111390&group_id=23919&atid=380010
                HostSetup hostSetup = new HostSetup();

                hostSetup.ApplicationBaseDirectory = Path.GetDirectoryName(assemblyPath);
                hostSetup.WorkingDirectory         = hostSetup.ApplicationBaseDirectory;
                hostSetup.ShadowCopy = true;
                hostSetup.ConfigurationFileLocation = ConfigurationFileLocation.AppBase;
                hostSetup.ProcessorArchitecture     = assemblyMetadata.ProcessorArchitecture;

                string configFile = assemblyPath + ".config";

                if (File.Exists(configFile))
                {
                    hostSetup.Configuration.ConfigurationXml = File.ReadAllText(configFile);
                }

                var hostFactory = (IHostFactory)RuntimeAccessor.ServiceLocator.ResolveByComponentId(IsolatedAppDomainHostFactory.ComponentId);

                using (IHost host = hostFactory.CreateHost(hostSetup, RuntimeAccessor.Logger))
                {
                    HostAssemblyResolverHook.InstallCallback(host);

                    Type loaderType = typeof(RemoteLoader);

                    using (RemoteLoader loader = (RemoteLoader)host.GetHostService().CreateInstance(
                               loaderType.Assembly.FullName,
                               loaderType.FullName).Unwrap())
                    {
                        // Attach ourself to get feedback
                        loader.Listener = this;

                        // Load the test assembly
                        loader.LoadAssembly(assemblyPath);

                        // Run the tests of that assembly
                        TextWriter consoleOutputWriter = new ContextualLogTextWriter(MarkupStreamNames.ConsoleOutput);
                        var        spec = new CallbackTestSpec(this);
                        loader.RunTests(spec, consoleOutputWriter);
                    }
                }

                return(topResult ?? new TestResult(TestOutcome.Error));
            }
Esempio n. 3
0
 public void TestDurationReported() {
    AssemblyFactory.Type = typeof(AssemblyMock);
    var remoteLoader = new RemoteLoader();
    var listener = new MyTestListener();
    remoteLoader.Listener = listener;
    remoteLoader.LoadAssembly(new AssemblyName{CodeBase = _assemblyPathName});
    remoteLoader.RunTests(new TestRun(new AllTestsCriterion()), new StringWriter());
    Assert.Greater(listener.Duration, 0);
 }