public string WrapTestExecutionWithReporting(string testExecutionExpression, ITestInfo test) { StringBuilder builder = new(); builder.AppendLine($"if ({_filterLocalIdentifier} is null || {_filterLocalIdentifier}.ShouldRunTest(@\"{test.ContainingType}.{test.Method}\", {test.TestNameExpression}))"); builder.AppendLine("{"); builder.AppendLine($"System.TimeSpan testStart = stopwatch.Elapsed;"); builder.AppendLine("try {"); builder.AppendLine($"System.Console.WriteLine(\"Running test: {{0}}\", {test.TestNameExpression});"); builder.AppendLine($"{_outputRecorderIdentifier}.ResetTestOutput();"); builder.AppendLine(testExecutionExpression); builder.AppendLine($"{_summaryLocalIdentifier}.ReportPassedTest({test.TestNameExpression}, \"{test.ContainingType}\", @\"{test.Method}\", stopwatch.Elapsed - testStart, {_outputRecorderIdentifier}.GetTestOutput());"); builder.AppendLine($"System.Console.WriteLine(\"Passed test: {{0}}\", {test.TestNameExpression});"); builder.AppendLine("}"); builder.AppendLine("catch (System.Exception ex) {"); builder.AppendLine($"{_summaryLocalIdentifier}.ReportFailedTest({test.TestNameExpression}, \"{test.ContainingType}\", @\"{test.Method}\", stopwatch.Elapsed - testStart, ex, {_outputRecorderIdentifier}.GetTestOutput());"); builder.AppendLine($"System.Console.WriteLine(\"Failed test: {{0}}\", {test.TestNameExpression});"); builder.AppendLine("}"); builder.AppendLine("}"); builder.AppendLine("else"); builder.AppendLine("{"); builder.AppendLine(GenerateSkippedTestReporting(test)); builder.AppendLine("}"); return(builder.ToString()); }
public bool TryCreateInstance(ITestInfo testInfo, ICollection <IMessage> messages, out object instance) { if (testInfo == null) { throw new ArgumentNullException(nameof(testInfo)); } if (messages == null) { throw new ArgumentNullException(nameof(messages)); } try { var typeParameters = testInfo.TypeArgs.ToArray(); var typeParametersStr = string.Join(", ", typeParameters.Select(i => i?.ToString() ?? "null").DefaultIfEmpty("empty").ToArray()); messages.Add(new Message(MessageType.Trace, Stage.Construction, $"Create instance of type {testInfo.Type.FullName} with parameters [{typeParametersStr}]")); instance = testInfo.Type.CreateInstance(typeParameters); messages.Add(new Message(MessageType.Trace, Stage.Construction, $"Instance #{instance.GetHashCode()} of type {testInfo.Type.FullName} was created")); return(true); } catch (Exception exception) { messages.Add(new Message(MessageType.Exception, Stage.Construction, exception.Message, exception.StackTrace)); instance = default(object); return(false); } }
public Case( [NotNull] IDisplayNameFactory displayNameFactory, [NotNull] ITestInfo testInfo) { _displayNameFactory = displayNameFactory; _testInfo = testInfo; if (displayNameFactory == null) { throw new ArgumentNullException(nameof(displayNameFactory)); } if (testInfo == null) { throw new ArgumentNullException(nameof(testInfo)); } Id = Guid.NewGuid(); Source = testInfo.Source; CodeFilePath = string.Empty; LineNumber = null; var typeArgs = testInfo.TypeArgs.Select(arg => arg.ToString()); var methodArgs = testInfo.MethodArgs.Select(arg => arg.ToString()); var methodGenerics = testInfo.Method.GenericArguments.Select(type => type.FullName); var args = string.Join(",", typeArgs.Concat(methodArgs).Concat(methodGenerics).ToArray()); FullyQualifiedName = $"{testInfo.Type.FullName}.{testInfo.Method.Name}({args})"; }
public IOSetupControl(ITestInfo testInfo) : this() { this.testInfo = testInfo; this.InputTextBox.Text = this.testInfo.Input; this.OutputTextBox.Text = this.testInfo.Output; }
public ConditionalTest(ITestInfo innerTest, string condition) { _innerTest = innerTest; _condition = condition; TestNameExpression = innerTest.TestNameExpression; DisplayNameForFiltering = innerTest.DisplayNameForFiltering; Method = innerTest.Method; ContainingType = innerTest.ContainingType; }
public void LoadTests(ITestInfo testinfomsg) { string[] files = System.IO.Directory.GetFiles(".", "*.dll"); foreach (string file in files) { try { Assembly assem = Assembly.LoadFrom(file); Type[] types = assem.GetExportedTypes(); foreach (Type t in types) { string dllName = t.Name + ".dll"; if (dllName != testinfomsg.testDriver) { continue; } Console.WriteLine("\n loading: \"{0}\"", file); if (t.IsClass && typeof(ITest).IsAssignableFrom(t)) // does this type derive from ITest ? { TestResult tr = new TestResult(); ITest tdr = (ITest)Activator.CreateInstance(t); // create instance of test driver tr.testName = testinfomsg.testName; tr.testResult = tdr.test() ? "passed" : "failed"; tr.testLog = tdr.getLog(); if (cb_ != null) { cb_.sendMessage(tr); } } } } catch (Exception ex) { Console.WriteLine("\n Execption: {0}", ex.Message); } } if (testinfomsg.testName == "ThirdTest") { TestResult tr = new TestResult(); tr.testName = "ThirdTest"; tr.testResult = "error"; tr.testLog = "missing files: cannot read the test code or driver."; if (cb_ != null) { cb_.sendMessage(tr); } } }
static void Main(string[] args) { Console.Write("\n Demonstrate loading and executing tests"); Console.Write("\n ========================================="); ITestInfo its = null; AssemLoadAndTest th = new AssemLoadAndTest(); th.LoadTests(its); Console.Write("\n couldn't load tests"); Console.Write("\n\n"); Console.ReadLine(); }
public MemberDataTest(ISymbol referencedMember, ITestInfo innerTest, string externAlias, string argumentLoopVarIdentifier) { TestNameExpression = innerTest.TestNameExpression; Method = innerTest.Method; ContainingType = innerTest.ContainingType; DisplayNameForFiltering = $"{ContainingType}.{Method}(...)"; _innerTest = innerTest; _loopVarIdentifier = argumentLoopVarIdentifier; string containingType = referencedMember.ContainingType.ToDisplayString(XUnitWrapperGenerator.FullyQualifiedWithoutGlobalNamespace); _memberInvocation = referencedMember switch { IPropertySymbol { IsStatic : true } => $"{externAlias}::{containingType}.{referencedMember.Name}",
public IResult Run(ITestInfo testInfo) { if (testInfo == null) { throw new ArgumentNullException(nameof(testInfo)); } var messages = new List <IMessage>(); if (testInfo.Ignore) { messages.Add(new Message(MessageType.State, Stage.Test, testInfo.IgnoreReason)); return(new Result(State.Skiped) { messages }); } if (!_instanceFactory.TryCreateInstance(testInfo, messages, out object testInstance)) { return(new Result(State.Failed) { messages }); } if (!_methodRunner.TryRun(testInfo, testInstance, messages)) { return(new Result(State.Failed) { messages }); } if (!_instanceDisposer.TryDispose(testInstance, messages)) { return(new Result(State.Failed) { messages }); } return(new Result(State.Passed) { messages }); }
public string WrapTestExecutionWithReporting(string testExecutionExpression, ITestInfo test) { StringBuilder builder = new(); builder.AppendLine($"if ({_filterLocalIdentifier} is null || {_filterLocalIdentifier}.ShouldRunTest(@\"{test.ContainingType}.{test.Method}\", {test.TestNameExpression}))"); builder.AppendLine("{"); builder.AppendLine($"TimeSpan testStart = stopwatch.Elapsed;"); builder.AppendLine("try {"); builder.AppendLine(testExecutionExpression); builder.AppendLine($"{_summaryLocalIdentifier}.ReportPassedTest({test.TestNameExpression}, \"{test.ContainingType}\", @\"{test.Method}\", stopwatch.Elapsed - testStart);"); builder.AppendLine("}"); builder.AppendLine("catch (System.Exception ex) {"); builder.AppendLine($"{_summaryLocalIdentifier}.ReportFailedTest({test.TestNameExpression}, \"{test.ContainingType}\", @\"{test.Method}\", stopwatch.Elapsed - testStart, ex);"); builder.AppendLine("}"); builder.AppendLine("}"); return(builder.ToString()); }
public bool TryRun(ITestInfo testInfo, object instance, ICollection <IMessage> messages) { if (testInfo == null) { throw new ArgumentNullException(nameof(testInfo)); } try { var method = testInfo.Method; messages.Add(new Message(MessageType.Trace, Stage.Construction, $"Run method {method.Name} for instance #{instance.GetHashCode()}")); method.Invoke(instance, testInfo.MethodArgs); messages.Add(new Message(MessageType.Trace, Stage.Construction, $"Method {method.Name} for instance #{instance.GetHashCode()} was finished")); } catch (Exception exception) { messages.Add(new Message(MessageType.Exception, Stage.Test, exception.Message, exception.StackTrace)); return(false); } return(true); }
public TestEnvironment(ITestInfo testInfo) { TestFixtureManager = PrepareTestFixture(testInfo.Class); PreparedTests = PrepareTest(testInfo.Class, testInfo.Method); }
public ConditionalTest(ITestInfo innerTest, Xunit.TestPlatforms platform) : this(innerTest, GetPlatformConditionFromTestPlatform(platform)) { }
internal TestEventArgs(ITestInfo testInfo, string fileName) { this.FileName = fileName; this.TestInfo = testInfo; }
public void AddItem(ITestInfo testInfo) { IOSetupControl control = new IOSetupControl(testInfo); control.DeleteButtonClick += this.ioSetupControl_DeleteButtonClick; this.IOControlsPanel.Children.Add(control); }
private void ToolBar1_ItemClick(ToolItem arg1, EventArgs arg2) { switch (arg1.Text) { case "控件": MControl.ReLoad(panel1, typeof(TestControl)); break; case "控件2": MControl.ReLoad(panel1, typeof(Control1)); break; case "数据": var server = new SQLiteService(); ITestInfo obj = new TestInfo(); //obj.Id = 1; //obj.Image = BitmapHelper.GetBitmapFormFile(@"D:\Tinn\DotNet\House\bin\Debug\Code\110031622_45259-02360-00.png"); //server.Insert(obj); ITestInfo info = server.FindById <TestInfo>(1); info.FindInfo = new FindInfo() { Id = 100 }; info.List.Add(new FindInfo()); info.List2 = new List <FindInfo>(); server.Update(info); TestBase b = new TestBase(); var b1 = (TestBase)info; b1.Clone(b); b.Id = 3; b.Clone(b1); var id = info.GetValue(nameof(TestInfo.FindInfo)); var obj3 = info.Clone(true); obj3.FindInfo.Id = 102; obj3.List.Clear(); obj3.List2.Add(new FindInfo()); ITestInfo obj4 = new TestInfo(); info.Clone(obj4, true); obj4.FindInfo.Id = 103; obj4.List.Clear(); obj4.List2.Add(new FindInfo()); Stopwatch sw = new Stopwatch(); sw.Restart(); var list = server.Find <TestInfo>("1=1 limit 10000"); Debug.WriteLine("FindList=>" + sw.ElapsedMilliseconds); sw.Restart(); //var dt3 = list.ToDataTable(); Debug.WriteLine("ToDataTable=>" + sw.ElapsedMilliseconds); var type = typeof(TestInfo); sw.Restart(); for (int i = 0; i < 10; i++) { var dt4 = list.ToDataTable(); } Debug.WriteLine("ToDataTable=>" + sw.ElapsedMilliseconds); sw.Restart(); for (int i = 0; i < 10; i++) { //var list4 = dt3.ToList<TestInfo>(); } Debug.WriteLine("ToDataTable2=>" + sw.ElapsedMilliseconds); sw.Restart(); for (int i = 0; i < 10 * 10; i++) { var ix = list.Find(c => c.Id == 1014509); } Debug.WriteLine("Find=>" + sw.ElapsedMilliseconds); var dict = list.Cast <TestInfo>().ToDictionary(o => o.Id, o => o); sw.Restart(); for (int i = 0; i < 10 * 10; i++) { if (dict.ContainsKey(1014509)) { var ix = dict[1014509]; } } Debug.WriteLine("Key=>" + sw.ElapsedMilliseconds); var map = new Hashtable(); map.Add(1, list[0]); map.Add("1", list[1]); var b2 = map[1]; var list3 = list.Clone(true); sw.Restart(); for (int i = 0; i < 100; i++) { list.Clone(list3); } Debug.WriteLine("Clone=>" + sw.ElapsedMilliseconds); sw.Restart(); for (int i = 0; i < 100; i++) { //var list3 = list.Clone2(true); list.Clone(list3); } Debug.WriteLine("Clone2=>" + sw.ElapsedMilliseconds); var dt2 = server.FindTable <ITestInfo>("1=1 limit 20"); var list2 = dt2.ToList <TestInfo>(); var list21 = dt2.ToList(type); sw.Restart(); list.Sort(nameof(TestInfo.UserType)); Debug.WriteLine("OrderBy2=>" + sw.ElapsedMilliseconds); sw.Restart(); var temp = list.AsParallel().OrderBy(c => c.Name); Debug.WriteLine("OrderBy1=>" + sw.ElapsedMilliseconds); sw.Restart(); var temp2 = list.AsParallel().OrderBy(c => c.Name).ToList(); Debug.WriteLine("ToList.Time=>" + sw.ElapsedMilliseconds); sw.Restart(); foreach (var item in temp) { } Debug.WriteLine("ToList.Time=>" + sw.ElapsedMilliseconds); //gridview1.DataSource = list; break; } }
public void Test <T>(string threadName, ITestInfo testInfo, LogTypes logType) { var name = testInfo.Name; var count = testInfo.Count; var text = testInfo.Text; var obj = default(T); var first = this.DataTableNewRow(results); var times = this.DataTableNewRow(results); this.SetCellValue(first, TimeName, DateTime.Now.ToString("HH:mm:ss")); this.SetCellValue(times, TimeName, DateTime.Now.ToString("HH:mm:ss")); this.SetCellValue(first, CaseName, name); this.SetCellValue(times, CaseName, name); this.SetCellValue(first, ModeName, $"deser (first)"); this.SetCellValue(times, ModeName, $"deser (the next {count} times)"); this.SetCellValue(first, ThreadName, threadName); this.SetCellValue(times, ThreadName, threadName); if ((logType & LogTypes.OnlyFirst) != 0) { this.DataTableAddRow(results, first); } if ((logType & LogTypes.OnlyTheNext) != 0) { this.DataTableAddRow(results, times); } foreach (var item in testers) { try { var stopwatch = Stopwatch.StartNew(); obj = item.Deserialize <T>(text); var time = stopwatch.ElapsedMilliseconds; if (testInfo.VerDeser(obj)) { this.SetCellValue(first, item.Name, time); } else { this.SetCellValue(first, item.Name, Error); } } catch (TimeoutException) { this.SetCellValue(first, item.Name, Timeout); } catch (Exception e) { Console.WriteLine($"{item.Name} -- deser -- {name} : \n{e}"); this.SetCellValue(first, item.Name, Exception); } if ((logType & LogTypes.OnlyTheNext) != 0) { try { obj = item.Deserialize <T>(text); if (testInfo.VerDeser(obj)) { var stopwatch = Stopwatch.StartNew(); for (int i = 0; i < count; i++) { item.Deserialize <T>(text); } var time = stopwatch.ElapsedMilliseconds; this.SetCellValue(times, item.Name, time); } else { this.SetCellValue(times, item.Name, Error); } } catch (TimeoutException) { this.SetCellValue(times, item.Name, Timeout); } catch (Exception) { this.SetCellValue(times, item.Name, Exception); } } } foreach (var item in testers) { try { obj = item.Deserialize <T>(text); if (testInfo.VerDeser(obj)) { break; } } catch (Exception) { } } first = this.DataTableNewRow(results); times = this.DataTableNewRow(results); this.SetCellValue(first, TimeName, DateTime.Now.ToString("HH:mm:ss")); this.SetCellValue(times, TimeName, DateTime.Now.ToString("HH:mm:ss")); this.SetCellValue(first, CaseName, name); this.SetCellValue(times, CaseName, name); this.SetCellValue(first, ModeName, $"ser (first)"); this.SetCellValue(times, ModeName, $"ser (the next {count} times)"); this.SetCellValue(first, ThreadName, threadName); this.SetCellValue(times, ThreadName, threadName); if ((logType & LogTypes.OnlyFirst) != 0) { this.DataTableAddRow(results, first); } if ((logType & LogTypes.OnlyTheNext) != 0) { this.DataTableAddRow(results, times); } foreach (var item in testers) { try { var stopwatch = Stopwatch.StartNew(); var json = item.Serialize(obj); var time = stopwatch.ElapsedMilliseconds; if (testInfo.VerSer(json)) { this.SetCellValue(first, item.Name, time); } else { this.SetCellValue(first, item.Name, Error); } } catch (TimeoutException) { this.SetCellValue(first, item.Name, Timeout); } catch (Exception e) { Console.WriteLine($"{item.Name} -- ser -- {name} : \n{e}"); this.SetCellValue(first, item.Name, Exception); } if ((logType & LogTypes.OnlyTheNext) != 0) { try { var json = item.Serialize(obj); if (testInfo.VerSer(json)) { var stopwatch = Stopwatch.StartNew(); for (int i = 0; i < count; i++) { item.Serialize(obj); } var time = stopwatch.ElapsedMilliseconds; this.SetCellValue(times, item.Name, time); } else { this.SetCellValue(times, item.Name, Error); } } catch (TimeoutException) { this.SetCellValue(times, item.Name, Timeout); } catch (Exception) { this.SetCellValue(times, item.Name, Exception); } } } }
private IList<ITestResult> RunParallel(ITestInfo test) { ITestEnvironment environment = new TestEnvironment(test); IList<ITestResult> results = environment.RunTestsInParallel(); return results; }
//if you want to run a certain subset of tests parallelizable public IList<ITestResult> RunTestParallel(ITestInfo test) { return RunParallel(test); }
public string GenerateSkippedTestReporting(ITestInfo skippedTest) => string.Empty;
public TestWithCustomDisplayName(ITestInfo inner, string displayName) { _inner = inner; DisplayNameForFiltering = displayName; }
public string CreateDisplayName(ITestInfo testInfo) { return($"{GetTypeName(testInfo.Type)}{GetArgString(testInfo.TypeArgs)}.{testInfo.Method.Name}{GetGenericArgsString(testInfo.Method.GenericArguments)}{GetMethodParamsString(testInfo.Method.Parameters, testInfo.MethodArgs)}"); }
public string WrapTestExecutionWithReporting(string testExecution, ITestInfo test) => testExecution;
public IList<ITestResult> RunTestInParallel(ITestInfo testInfo) { return RunAllTestsInParallel(); }
public string GenerateSkippedTestReporting(ITestInfo skippedTest) { return($"{_summaryLocalIdentifier}.ReportSkippedTest({skippedTest.TestNameExpression}, \"{skippedTest.ContainingType}\", \"{skippedTest.Method}\", System.TimeSpan.Zero, string.Empty);"); }
public IOSetupControl() { this.InitializeComponent(); this.testInfo = CoreAccessor.CreateTestInfo(); }