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); var specsByContext = specsToRun.GroupBy(x => x.ContainerTypeFullName); mspecRunner.StartRun(assemblyToRun); foreach (var specs in specsByContext) { var fields = specs.Select(x => x.FieldName); mspecRunner.RunType(assemblyToRun, assemblyToRun.GetType(specs.Key), fields.ToArray()); } } catch (Exception e) { specificationRunListener.OnFatalError(new ExceptionResult(e)); } finally { if (mspecRunner != null && assemblyToRun != null) { mspecRunner.EndRun(assemblyToRun); } } }
/// <summary> /// Run specifics specs. This method is available to support IDE integration scenarios, where users can run /// a specific test only. /// </summary> /// <param name="assembly"></param> /// <param name="specifications">A spec full name "namespace.type.field_name". </param> /// <remarks>This method supports fields that actually come from Behaviors </remarks> public void RunSpecs(Assembly assembly, IEnumerable <string> specifications) { try { runner.StartRun(assembly); foreach (var specsByType in specifications.GroupBy(spec => spec.Substring(0, spec.LastIndexOf(".")))) { var fullTypeName = specsByType.Key; var specNames = specsByType.Select(spec => spec.Substring(spec.LastIndexOf(".") + 1, spec.Length - 1 - spec.LastIndexOf("."))); runner.RunType(assembly, assembly.GetType(fullTypeName), specNames); } } finally { runner.EndRun(assembly); } }