public void QueueTest(TestFixture instance, MethodInfo method) { var unitTest = new UnitTest { Instance = instance, Method = method }; unitTests.Add(unitTest); instance.SetUnitTest(unitTest); Element fixtureRow; if (!fixtureRows.TryGetValue(instance.GetType(), out fixtureRow)) { var nameCell = CreateFixtureDataCell(instance.GetType().FullName); var passedCell = CreateFixtureDataCell(); var failedCell = CreateFixtureDataCell(); var erroredCell = CreateFixtureDataCell(); fixtureRow = Browser.Document.CreateElement("tr"); fixtureRow.AppendChild(nameCell); fixtureRow.AppendChild(passedCell); fixtureRow.AppendChild(failedCell); fixtureRow.AppendChild(erroredCell); table.AppendChild(fixtureRow); fixtureRows[instance.GetType()] = fixtureRow; } var testNameCell = CreateDataCell(unitTest.Method.Name); var testPassedCell = CreateDataCell(); var testFailedCell = CreateDataCell(); var testErroredCell = CreateDataCell(); var testRow = Browser.Document.CreateElement("tr"); testRow.AppendChild(testNameCell); testRow.AppendChild(testPassedCell); testRow.AppendChild(testFailedCell); testRow.AppendChild(testErroredCell); testRows[unitTest.Method] = testRow; table.AppendChild(testRow); }
public void SetUnitTest(UnitTest unitTest) { this.unitTest = unitTest; }
public async void RunTest(UnitTest test) { try { var result = test.Method.Invoke(test.Instance, new object[0]); if (test.Method.ReturnType != typeof(void) && typeof(Task).IsAssignableFrom(test.Method.ReturnType)) { var task = (Task)result; await task; } } catch (Exception e) { test.Exception = e; if (e.As<JsObject>().member("GetType") == null) e = new JsException(e.As<JsError>()); Console.WriteLine(e.As<JsObject>().toString()); } ReportTest(test); }
private void ReportTest(UnitTest test) { Console.WriteLine(test.Method); var passed = test.Assertions.Where(x => x.Status == AssertionStatus.Passed).ToArray(); var failed = test.Assertions.Where(x => x.Status == AssertionStatus.Failed).ToArray(); var errored = test.Assertions.Where(x => x.Status == AssertionStatus.Errored).ToArray(); Console.WriteLine("Passed: " + passed.Length + ", Failed: " + failed.Length + ", Errored: " + errored.Length); var testRow = testRows[test.Method]; testRow.Children[1].Children[0].AppendChild(Browser.Document.CreateTextNode(passed.Length.ToString())); testRow.Children[2].Children[0].AppendChild(Browser.Document.CreateTextNode(failed.Length.ToString())); testRow.Children[3].Children[0].AppendChild(Browser.Document.CreateTextNode(errored.Length.ToString())); outstandingTests.Remove(test); if (failed.Any() || errored.Any()) { for (var i = 0; i < testRow.Children.Length; i++) { testRow.Children[i].Style.BackgroundColor = "red"; } } if (!outstandingTests.Any(x => x.Instance.GetType().FullName == test.Instance.GetType().FullName)) { var fixtureTestAssertions = unitTests.Where(x => x.Instance.GetType().FullName == test.Instance.GetType().FullName).SelectMany(x => x.Assertions).ToArray(); var fixturePassedCount = fixtureTestAssertions.Count(x => x.Status == AssertionStatus.Passed); var fixtureFailedCount = fixtureTestAssertions.Count(x => x.Status == AssertionStatus.Failed); var fixtureErroredCount = fixtureTestAssertions.Count(x => x.Status == AssertionStatus.Errored); var fixtureRow = fixtureRows[test.Instance.GetType()]; fixtureRow.Children[1].Children[0].AppendChild(Browser.Document.CreateTextNode(fixturePassedCount.ToString())); fixtureRow.Children[2].Children[0].AppendChild(Browser.Document.CreateTextNode(fixtureFailedCount.ToString())); fixtureRow.Children[3].Children[0].AppendChild(Browser.Document.CreateTextNode(fixtureErroredCount.ToString())); } if (!outstandingTests.Any()) Finished(); }