Exemplo n.º 1
0
        protected override object CreateTestClass()
        {
            var testClass = base.CreateTestClass();

            (testClass as ILoggedTest).Initialize(
                TestMethod,
                TestMethodArguments,
                _output ?? ConstructorArguments.SingleOrDefault(a => typeof(ITestOutputHelper).IsAssignableFrom(a.GetType())) as ITestOutputHelper);

            if (testClass is LoggedTestBase loggedTestBase)
            {
                // Used for testing
                loggedTestBase.RetryContext = _retryContext;

                if (_retryContext != null)
                {
                    // Log retry attempt as warning
                    if (_retryContext.CurrentIteration > 0)
                    {
                        loggedTestBase.Logger.LogWarning($"{TestMethod.Name} failed and retry conditions are met, re-executing. The reason for failure is {_retryContext.Reason}.");
                    }

                    // Save the test class instance for non-static predicates
                    _retryContext.TestClassInstance = testClass;
                }
            }

            return(testClass);
        }
Exemplo n.º 2
0
        protected override object CreateTestClass()
        {
            var testClass = base.CreateTestClass();

            if (testClass is ILoggedTest loggedTest)
            {
                loggedTest.Initialize(
                    TestMethod,
                    TestMethodArguments,
                    _output ?? ConstructorArguments.SingleOrDefault(a => typeof(ITestOutputHelper).IsAssignableFrom(a.GetType())) as ITestOutputHelper);
            }

            return(testClass);
        }
        protected async override Task <Tuple <decimal, string> > InvokeTestAsync(ExceptionAggregator aggregator)
        {
            var testOutputHelper = ConstructorArguments.SingleOrDefault(a => typeof(TestOutputHelper).IsAssignableFrom(a.GetType())) as TestOutputHelper
                                   ?? new TestOutputHelper();

            testOutputHelper.Initialize(MessageBus, Test);

            var executionTime = await InvokeTestMethodAsync(aggregator, testOutputHelper);

            var output = testOutputHelper.Output;

            testOutputHelper.Uninitialize();

            return(Tuple.Create(executionTime, output));
        }
Exemplo n.º 4
0
        protected override object CreateTestClass()
        {
            var testClass = base.CreateTestClass();

            if (testClass is LoggedTest loggedTestClass)
            {
                var classType         = loggedTestClass.GetType();
                var logLevelAttribute = TestMethod.GetCustomAttribute <LogLevelAttribute>() as LogLevelAttribute;
                var testName          = TestMethodArguments.Aggregate(TestMethod.Name, (a, b) => $"{a}-{(b ?? "null")}");

                // Try resolving ITestOutputHelper from constructor arguments
                loggedTestClass.TestOutputHelper = ConstructorArguments?.SingleOrDefault(a => typeof(ITestOutputHelper).IsAssignableFrom(a.GetType())) as ITestOutputHelper;

                var useShortClassName = TestMethod.DeclaringType.GetCustomAttribute <ShortClassNameAttribute>()
                                        ?? TestMethod.DeclaringType.Assembly.GetCustomAttribute <ShortClassNameAttribute>();
                var resolvedClassName = useShortClassName == null ? classType.FullName : classType.Name;
                // None resolved so create a new one and retain a reference to it for initialization/uninitialization
                if (loggedTestClass.TestOutputHelper == null)
                {
                    loggedTestClass.TestOutputHelper = _output = new TestOutputHelper();
                    _output.Initialize(MessageBus, Test);
                }

                AssemblyTestLog
                .ForAssembly(classType.GetTypeInfo().Assembly)
                .StartTestLog(
                    loggedTestClass.TestOutputHelper,
                    resolvedClassName,
                    out var loggerFactory,
                    logLevelAttribute?.LogLevel ?? LogLevel.Trace,
                    out var resolvedTestName,
                    testName);

                // internal for testing
                loggedTestClass.ResolvedTestMethodName = resolvedTestName;
                loggedTestClass.ResolvedTestClassName  = resolvedClassName;

                loggedTestClass.LoggerFactory = loggerFactory;
                loggedTestClass.Logger        = loggerFactory.CreateLogger(classType);
                loggedTestClass.TestSink      = new TestSink();
                loggerFactory.AddProvider(new TestLoggerProvider(loggedTestClass.TestSink));

                loggedTestClass.AdditionalSetup();
            }

            return(testClass);
        }
Exemplo n.º 5
0
        protected override object CreateTestClass()
        {
            var testClass = base.CreateTestClass();

            (testClass as ILoggedTest).Initialize(
                TestMethod,
                TestMethodArguments,
                _output ?? ConstructorArguments.SingleOrDefault(a => typeof(ITestOutputHelper).IsAssignableFrom(a.GetType())) as ITestOutputHelper);

            if (testClass is LoggedTestBase loggedTestBase)
            {
                // Used for testing
                loggedTestBase.RepeatContext = _repeatContext;
            }

            return(testClass);
        }