Exemplo n.º 1
0
        public static List <string> GetExtensions(ITestDiscoverer discoverer)
        {
            var atts       = discoverer.GetType().GetCustomAttributes(true).OfType <FileExtensionAttribute>().ToList();
            var extensions = atts.Select(att => att.FileExtension).ToList();

            return(extensions);
        }
Exemplo n.º 2
0
        public static List <string> GetSources(string folder, ITestDiscoverer discoverer)
        {
            var extensions = GetExtensions(discoverer);
            var sources    = Directory.EnumerateFiles(folder).Where(file => extensions.Contains(Path.GetExtension(file))).ToList();

            return(sources);
        }
Exemplo n.º 3
0
        private static void DiscoverTests(TestEnvironment testEnv, string[] sources, MockRunSettings runSettings, TestInfo[] expectedTests)
        {
            var discoveryContext = new MockDiscoveryContext(runSettings);
            var discoverySink    = new MockTestCaseDiscoverySink();
            var logger           = new MockMessageLogger();

            ITestDiscoverer discoverer = null;

            switch (testEnv.TestFramework)
            {
            case FrameworkPytest:
                discoverer = new PytestTestDiscoverer();
                break;

            case FrameworkUnittest:
                discoverer = new UnittestTestDiscoverer();
                break;

            default:
                Assert.Fail($"unknown testframework: {testEnv.TestFramework.ToString()}");
                break;
            }

            discoverer.DiscoverTests(sources, discoveryContext, logger, discoverySink);

            ValidateDiscoveredTests(testEnv.TestFramework, discoverySink.Tests, expectedTests);
        }
 public void VerifyLoading()
 {
     // Load the NUnit empty-assembly.dll once for this test
     nunittestDiscoverer = ((ITestDiscoverer) new NUnitTestDiscoverer());
     nunittestDiscoverer.DiscoverTests(
         new[] { EmptyAssemblyPath },
         new FakeDiscoveryContext(),
         new MessageLoggerStub(),
         this);
 }
Exemplo n.º 5
0
 public void VerifyLoading()
 {
     // Load the NUnit empty-assembly.dll once for this test
     nunittestDiscoverer = ((ITestDiscoverer)new NUnit3TestDiscoverer());
     nunittestDiscoverer.DiscoverTests(
         new[] { EmptyAssemblyPath}, 
         new FakeDiscoveryContext(), 
         new MessageLoggerStub(), 
         this);
 }
Exemplo n.º 6
0
        public void LoadMockassembly()
        {
            // Sanity check to be sure we have the correct version of mock-assembly.dll
            Assert.That(NUnit.Tests.Assemblies.MockAssembly.Tests, Is.EqualTo(31),
                        "The reference to mock-assembly.dll appears to be the wrong version");

            // Load the NUnit mock-assembly.dll once for this test, saving
            // the list of test cases sent to the discovery sink
            nunittestDiscoverer = ((ITestDiscoverer) new NUnit3TestDiscoverer());
            nunittestDiscoverer.DiscoverTests(new[] { MockAssemblyPath }, null, this, this);
        }
        public void LoadMockassembly()
        {
            // Sanity check to be sure we have the correct version of mock-assembly.dll
            Assert.That(NUnit.Tests.Assemblies.MockAssembly.Tests, Is.EqualTo(31),
                "The reference to mock-assembly.dll appears to be the wrong version");

            // Load the NUnit mock-assembly.dll once for this test, saving
            // the list of test cases sent to the discovery sink
            nunittestDiscoverer = ((ITestDiscoverer)new NUnit3TestDiscoverer());
            nunittestDiscoverer.DiscoverTests(new[] { MockAssemblyPath}, null, this, this);
        }
Exemplo n.º 8
0
        static TestAdapter()
        {
            var testPlatformAdapterFileName = GetFileNames("DevTeam.TestPlatformAdapter.dll").First();
            var icoConfigFileName           = GetFileNames("DevTeam.TestEngine.dll.ioc").First();

#if !NETCOREAPP1_0
            AppDomain.CurrentDomain.AssemblyResolve += (sender, args) =>
            {
                var assemblyName = new AssemblyName(args.Name);
                foreach (var fileName in GetFileNames(assemblyName.Name + ".dll"))
                {
                    try
                    {
                        return(Assembly.LoadFile(fileName));
                    }
                    catch
                    {
                        // ignored
                    }
                }

                return(null);
            };

            var testPlatformAdapterAssembly = Assembly.LoadFile(testPlatformAdapterFileName);
            var testPlatformAdapterType     = testPlatformAdapterAssembly.GetTypes().Single(i => i.Name == "TestAdapter");
#else
            AssemblyLoadContext.Default.Resolving += (ctx, assemblyName) =>
            {
                foreach (var fileName in GetFileNames(assemblyName.Name + ".dll"))
                {
                    try
                    {
                        return(ctx.LoadFromAssemblyPath(fileName));
                    }
                    catch
                    {
                        // ignored
                    }
                }

                return(null);
            };

            var testPlatformAdapterAssembly = AssemblyLoadContext.Default.LoadFromAssemblyPath(testPlatformAdapterFileName);
            var testPlatformAdapterType     = testPlatformAdapterAssembly.ExportedTypes.Single(i => i.Name == "TestAdapter");
#endif
            var adapter = Activator.CreateInstance(testPlatformAdapterType, icoConfigFileName, ExecutorUri);
            TestDiscoverer = (ITestDiscoverer)adapter;
            TestExecutor   = (ITestExecutor)adapter;
        }
Exemplo n.º 9
0
        /// <summary>
        /// This is the equivalent of "RunAll" functionality
        /// </summary>
        /// <param name="sources">Refers to the list of test sources passed to the test adapter from the client.  (Client could be VS or command line)</param>
        /// <param name="runContext">Defines the settings related to the current run</param>
        /// <param name="frameworkHandle">Handle to framework.  Used for recording results</param>
        public void RunTests(IEnumerable <string> sources, ITestDiscoverer discoverer)
        {
            ValidateArg.NotNull(sources, nameof(sources));
            ValidateArg.NotNull(discoverer, nameof(discoverer));

            var receiver = new TestReceiver();

            discoverer.DiscoverTests(sources, /*discoveryContext*/ null, this.frameworkHandle, receiver);

            if (this.cancelRequested.WaitOne(0))
            {
                return;
            }

            this.RunTests(receiver.Tests);
        }
Exemplo n.º 10
0
        public void LoadMockassembly()
        {
            // Sanity check to be sure we have the correct version of mock-assembly.dll
            Assert.That(NUnit.Tests.Assemblies.MockAssembly.TestsAtRuntime, Is.EqualTo(NUnit.Tests.Assemblies.MockAssembly.Tests),
                        "The reference to mock-assembly.dll appears to be the wrong version");

            TestCases = new List <TestCase>();

            // Load the NUnit mock-assembly.dll once for this test, saving
            // the list of test cases sent to the discovery sink
            nunittestDiscoverer = ((ITestDiscoverer) new NUnit3TestDiscoverer());
            nunittestDiscoverer.DiscoverTests(
                new[] { MockAssemblyPath },
                _context,
                new MessageLoggerStub(),
                this);
        }
Exemplo n.º 11
0
 public void VerifyLoading()
 {
     // Load the NUnit empty-assembly.dll once for this test
     nunittestDiscoverer = ((ITestDiscoverer) new NUnit3TestDiscoverer());
     nunittestDiscoverer.DiscoverTests(new[] { EmptyAssemblyPath }, null, this, this);
 }
Exemplo n.º 12
0
 public TestRunner()
 {
     _discoverer = null;
 }
Exemplo n.º 13
0
 public TestRunner(ITestDiscoverer discoverer)
 {
     _discoverer = discoverer;
 }
 public void VerifyLoading()
 {
     // Load the NUnit empty-assembly.dll once for this test
     nunittestDiscoverer = ((ITestDiscoverer)new NUnit3TestDiscoverer());
     nunittestDiscoverer.DiscoverTests(new[] { EmptyAssemblyPath}, null, this, this);
 }