public void Setup() { formatter = new XUnitFormatter(); outDirPath = Path.Combine( Path.GetTempPath(), "NSpec.Tests", nameof(describe_XUnitFormatter)); Directory.CreateDirectory(outDirPath); outFilePath = Path.Combine( outDirPath, Path.ChangeExtension(Path.GetRandomFileName(), "xml")); formatter.Options = new Dictionary <string, string>() { { "file", outFilePath }, }; var invocation = new RunnerInvocation( dll: typeof(describe_XUnitFormatter).GetTypeInfo().Assembly.Location, tags: typeof(xunit_formatter_sample_spec).Name, formatter: formatter, failFast: false); contexts = invocation.Run(); }
static void Main(string[] args) { var shouldShowHelp = false; var useXUnitFormatter = false; var options = new OptionSet { { "h|help", "show this message and exit", h => shouldShowHelp = h != null }, { "f|formatter", "console (default) | xunit", f => useXUnitFormatter = string.Compare(f, "xunit", StringComparison.InvariantCultureIgnoreCase) == 0 } }; if (shouldShowHelp) { Console.WriteLine("Usage: [OPTIONS] path/to/test.assembly.dll path/to/test.2.assembly.dll"); Console.WriteLine(); Console.WriteLine("Options:"); options.WriteOptionDescriptions(Console.Out); } IFormatter formatter = null; if (useXUnitFormatter) { formatter = new XUnitFormatter(); } else { formatter = new ConsoleFormatter(); } IEnumerable <FileInfo> extra; try { extra = options.Parse(args).Select(n => new FileInfo(n)).Where(n => n.Exists); foreach (var asm in extra) { var invocation = new RunnerInvocation(asm.FullName, null, formatter, false); var result = invocation.Run(); var failes = result.Failures().ToArray(); if (failes.Any()) { throw new Exception($"NSpec run of {asm} reported Failures"); } } } catch (OptionException e) { Console.WriteLine(e.Message); Console.WriteLine("Try `--help' for more information."); return; } }
private IFormatter GetFormatter(RunnerOptions options) { switch (options.FormatterFlag) { case Formatter.XUnit: var formatter = new XUnitFormatter(); formatter.Options.Add("file", options.GetOutputFileName("xml")); return(formatter); default: return(new ConsoleFormatter()); } }
public void Setup() { formatter = new XUnitFormatter(); Run(typeof(xunit_formatter_sample_spec)); }