public void ParseEnvironmentStringsTest_ValidEnvironments_ReturnValidRunConfiguration()
        {
            IList <string> environments = new List <string> {
                MobileEnvironment,
                WebEnvironment
            };

            TestInfo mockTesInfo = new TestInfo("c:\tests\test1",
                                                "c:\tests\test1", "1", "Test1");

            mockTesInfo.ReportPath = mockTesInfo.TestPath;

            ParallelTestRunConfiguration configuration = null;

            try
            {
                configuration = ParallelRunnerEnvironmentUtil.
                                ParseEnvironmentStrings(environments, mockTesInfo);
            }
            catch (ParallelRunnerConfigurationException)
            {
                // since the environments are valid there should be no exception
                Assert.Fail();
            }

            // report paths should be equal
            Assert.AreEqual(mockTesInfo.ReportPath, configuration.reportPath);

            // we have two parallel runs
            // one for web and one for mobile
            Assert.AreEqual(2, configuration.parallelRuns.Length);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Parse all of the provided environment strings for this test.
        /// </summary>
        /// <param name="environments">the environments list</param>
        /// <param name="testInfo">the test information </param>
        /// <returns>the parallel test run configuration</returns>
        public static ParallelTestRunConfiguration ParseEnvironmentStrings(IEnumerable <string> environments, TestInfo testInfo)
        {
            var parallelTestRunConfiguration = new ParallelTestRunConfiguration
            {
                reportPath = testInfo.ReportPath
            };

            var items = new List <ParallelTestRunConfigurationItem>();

            foreach (var env in environments)
            {
                var environment = new ParallelTestRunConfiguraion.Environment();

                // try to determine the environment type
                var type = GetEnvironmentType(env);

                if (type == EnvironmentType.MOBILE)
                {
                    environment.mobile = ParseMobileEnvironment(env);

                    if (environment.mobile == null)
                    {
                        throw new ParallelRunnerConfigurationException("Invalid mobile configuration provided: " + env);
                    }
                }
                else if (type == EnvironmentType.WEB)
                {
                    environment.web = ParseWebEnvironment(env);

                    if (environment.web == null)
                    {
                        throw new ParallelRunnerConfigurationException("Invalid web configuration provided: " + env);
                    }
                }
                else
                {
                    // environment might be an empty string, just ignore it
                    continue;
                }

                var item = new ParallelTestRunConfigurationItem
                {
                    test       = testInfo.TestPath,
                    env        = environment,
                    reportPath = testInfo.TestPath
                };

                items.Add(item);
            }

            parallelTestRunConfiguration.parallelRuns = items.ToArray();

            return(parallelTestRunConfiguration);
        }
        public void ParseEnvironmentStringsTest_InvalidEnvironments_ThrowException()
        {
            // the list of supported browsers
            IList <string> environments = new List <string> {
                "browser: unknown",
            };

            TestInfo mockTesInfo = new TestInfo("c:\tests\test1",
                                                "c:\tests\test1", "1", "Test1");

            mockTesInfo.ReportPath = mockTesInfo.TestPath;

            ParallelTestRunConfiguration configuration = ParallelRunnerEnvironmentUtil.
                                                         ParseEnvironmentStrings(environments, mockTesInfo);
        }
        public void ParseEnvironmentStringsTest_UnknownEnvironments_ReturnEmptyConfiguration()
        {
            // the list of supported browsers
            IList <string> environments = new List <string> {
                "test: ",
            };

            TestInfo mockTesInfo = new TestInfo("c:\tests\test1",
                                                "c:\tests\test1", "1", "Test1");

            mockTesInfo.ReportPath = mockTesInfo.TestPath;
            ParallelTestRunConfiguration configuration = null;

            try
            {
                configuration = ParallelRunnerEnvironmentUtil.
                                ParseEnvironmentStrings(environments, mockTesInfo);
            }catch (ParallelRunnerConfigurationException)
            {
                Assert.Fail();
            }

            Assert.AreEqual(0, configuration.parallelRuns.Length);
        }