示例#1
0
 /// <summary>
 /// Instantiates a TestRunner based on the environment variables.
 /// </summary>
 /// <returns>A TestRunner instance.</returns>
 public static ITestRunner NewTestRunner()
 {
     if (RunOnYarn())
     {
         throw new NotImplementedException("Running tests on YARN is not supported yet.");
     }
     return(LocalTestRunner.GetLocalTestRunner());
 }
示例#2
0
        /// <summary>
        /// Run the tests.
        /// </summary>
        /// <param name="commandLineOptions"></param>
        /// <returns></returns>
        /// <exception cref="CommandLineArgumentException">
        /// One or more arguments on the command line were invalid.
        /// </exception>
        public static int OnRunTests(CommandLineOptions commandLineOptions)
        {
            TestEventListener testEventListener;

            try
            {
                ApiBestPracticeTestBase.Register(
                    File.ReadAllText(commandLineOptions.SwaggerFilePath),
                    commandLineOptions.BaseUrl != null ? new Uri(commandLineOptions.BaseUrl) : null);
            }
            catch (IOException ex)
            {
                throw new CommandLineArgumentException(
                          $"Swagger file '{commandLineOptions.SwaggerFilePath}' does not exist or cannot be read", ex);
            }
            catch (UnauthorizedAccessException ex)
            {
                throw new CommandLineArgumentException(
                          $"Swagger file '{commandLineOptions.SwaggerFilePath}' cannot be accessed", ex);
            }
            catch (UriFormatException ex)
            {
                throw new CommandLineArgumentException(
                          $"Base URL '{commandLineOptions.BaseUrl}' is not a valid URI", ex);
            }

            testEventListener = new TestEventListener();
            testEventListener.OnTestCaseResult += TestEventListener_OnTestCaseResult;
            FailedTestCount = 0;

            ApiBestPracticeTestBase.Register(
                File.ReadAllText(commandLineOptions.SwaggerFilePath),
                commandLineOptions.BaseUrl != null ? new Uri(commandLineOptions.BaseUrl) : null);

            using (ITestEngine engine = TestEngineActivator.CreateInstance())
                using (ITestEngineRunner testRunner = new LocalTestRunner(engine.Services, new TestPackage("jab.dll")))
                {
                    testRunner.Run(testEventListener, TestFilter.Empty);
                }

            return(FailedTestCount > 0 ? ExitCodes.TestFailed : ExitCodes.Success);
        }