private TestCase ConvertSpecificationToTestCase(SpecificationInfo specification, Settings settings) { VisualStudioTestIdentifier vsTestId = specification.ToVisualStudioTestIdentifier(currentContext); return(new TestCase(vsTestId.FullyQualifiedName, this.executorUri, this.assemblyPath) { DisplayName = settings.DisableFullTestNameInOutput ? specification.Name : $"{this.currentContext?.TypeName}.{specification.FieldName}", }); }
public SingleBehaviorTestRunListenerWrapper(ISpecificationRunListener runListener, VisualStudioTestIdentifier listenFor) { if (listenFor == null) { throw new ArgumentNullException(nameof(listenFor)); } if (runListener == null) { throw new ArgumentNullException(nameof(runListener)); } this.runListener = runListener; this.listenFor = listenFor; }
public void RunTestsInAssembly(string pathToAssembly, IEnumerable <VisualStudioTestIdentifier> specsToRun, ISpecificationRunListener specificationRunListener) { DefaultRunner mspecRunner = null; Assembly assemblyToRun = null; try { assemblyToRun = AssemblyHelper.Load(pathToAssembly); mspecRunner = CreateRunner(assemblyToRun, specificationRunListener); IEnumerable <Context> specificationContexts = new AssemblyExplorer().FindContextsIn(assemblyToRun) ?? Enumerable.Empty <Context>(); Dictionary <string, Context> contextMap = specificationContexts.ToDictionary(c => c.Type.FullName, StringComparer.Ordinal); // We use explicit assembly start and end to wrap the RunMember loop mspecRunner.StartRun(assemblyToRun); foreach (VisualStudioTestIdentifier test in specsToRun) { Context context = contextMap[test.ContainerTypeFullName]; if (context == null) { continue; } Specification specification = context.Specifications.SingleOrDefault(spec => spec.FieldInfo.Name.Equals(test.FieldName, StringComparison.Ordinal)); if (specification is BehaviorSpecification) { // MSpec doesn't expose any way to run an an "It" coming from a "[Behavior]", so we have to do some trickery VisualStudioTestIdentifier listenFor = specification.ToVisualStudioTestIdentifier(context); DefaultRunner behaviorRunner = new DefaultRunner(new SingleBehaviorTestRunListenerWrapper(specificationRunListener, listenFor), RunOptions.Default); behaviorRunner.RunMember(assemblyToRun, context.Type.GetTypeInfo()); } else { mspecRunner.RunMember(assemblyToRun, specification.FieldInfo); } } } catch (Exception e) { specificationRunListener.OnFatalError(new ExceptionResult(e)); } finally { if (mspecRunner != null && assemblyToRun != null) { mspecRunner.EndRun(assemblyToRun); } } }