Пример #1
0
        public void RunTestsForTestShouldRunTestsWithSpecifiedNumberOfWorkers()
        {
            var testCase1 = this.GetTestCase(typeof(DummyTestClassForParallelize), "TestMethod1");
            var testCase2 = this.GetTestCase(typeof(DummyTestClassForParallelize2), "TestMethod1");
            var testCase3 = this.GetTestCase(typeof(DummyTestClassForParallelize3), "TestMethod1");

            TestCase[] tests = new[] { testCase1, testCase2, testCase3 };
            this.runContext.MockRunSettings.Setup(rs => rs.SettingsXml).Returns(
                @"<RunSettings> 
                                              <MSTest>
                                                 <Parallelize>
                                                   <Workers>3</Workers>
                                                 </Parallelize>
                                              </MSTest>
                                            </RunSettings>");

            try
            {
                MSTestSettings.PopulateSettings(this.runContext);
                this.TestExecutionManager.RunTests(tests, this.runContext, this.frameworkHandle, new TestRunCancellationToken());

                var allThreadIds = new HashSet <int>(DummyTestClassForParallelize.ThreadIds);
                allThreadIds.UnionWith(DummyTestClassForParallelize2.ThreadIds);
                allThreadIds.UnionWith(DummyTestClassForParallelize3.ThreadIds);

                Assert.AreEqual(3, allThreadIds.Count);
            }
            finally
            {
                DummyTestClassForParallelize.Cleanup();
                DummyTestClassForParallelize2.Cleanup();
                DummyTestClassForParallelize3.Cleanup();
            }
        }
Пример #2
0
        public void RunTestsForTestShouldRunTestsByMethodLevelWhenSpecified()
        {
            var testCase11 = this.GetTestCase(typeof(DummyTestClassForParallelize), "TestMethod1");
            var testCase12 = this.GetTestCase(typeof(DummyTestClassForParallelize), "TestMethod2");

            TestCase[] tests = new[] { testCase11, testCase12 };
            this.runContext.MockRunSettings.Setup(rs => rs.SettingsXml).Returns(
                @"<RunSettings> 
                                              <MSTest>
                                                 <Parallelize>
                                                   <Workers>2</Workers>
                                                   <Scope>MethodLevel</Scope>
                                                 </Parallelize>
                                              </MSTest>
                                            </RunSettings>");

            try
            {
                MSTestSettings.PopulateSettings(this.runContext);
                this.TestExecutionManager.RunTests(tests, this.runContext, this.frameworkHandle, new TestRunCancellationToken());

                Assert.AreEqual(2, DummyTestClassForParallelize.ThreadIds.Count);
            }
            finally
            {
                DummyTestClassForParallelize.Cleanup();
            }
        }
Пример #3
0
        public void RunTestsForTestShouldPreferParallelSettingsFromRunSettingsOverAssemblyLevelAttributes()
        {
            var testCase1 = this.GetTestCase(typeof(DummyTestClassForParallelize), "TestMethod1");
            var testCase2 = this.GetTestCase(typeof(DummyTestClassForParallelize), "TestMethod2");

            TestCase[] tests = new[] { testCase1, testCase2 };
            this.runContext.MockRunSettings.Setup(rs => rs.SettingsXml).Returns(
                @"<RunSettings> 
                                              <MSTest>
                                                 <Parallelize>
                                                   <Workers>2</Workers>
                                                   <Scope>MethodLevel</Scope>
                                                 </Parallelize>
                                              </MSTest>
                                            </RunSettings>");

            try
            {
                MSTestSettings.PopulateSettings(this.runContext);
                var testablePlatformService = this.SetupTestablePlatformService();
                testablePlatformService.SetupMockReflectionOperations();

                var originalReflectionOperation = new ReflectionOperations();

                testablePlatformService.MockReflectionOperations.Setup(
                    ro => ro.GetCustomAttributes(It.IsAny <Assembly>(), It.IsAny <Type>())).
                Returns((Assembly asm, Type type) =>
                {
                    if (type.FullName.Equals(typeof(UTF.ParallelizeAttribute).FullName))
                    {
                        return(new object[] { new UTF.ParallelizeAttribute {
                                                  Workers = 1
                                              } });
                    }

                    return(originalReflectionOperation.GetCustomAttributes(asm, type));
                });

                testablePlatformService.MockReflectionOperations.Setup(
                    ro => ro.GetCustomAttributes(It.IsAny <MemberInfo>(), It.IsAny <bool>())).
                Returns((MemberInfo memberInfo, bool inherit) =>
                {
                    return(originalReflectionOperation.GetCustomAttributes(memberInfo, inherit));
                });

                this.TestExecutionManager.RunTests(tests, this.runContext, this.frameworkHandle, new TestRunCancellationToken());

                Assert.AreEqual(2, DummyTestClassForParallelize.ThreadIds.Count);
            }
            finally
            {
                DummyTestClassForParallelize.Cleanup();
            }
        }