public async Task<TestRun> Run(TestContext context) { var start = DateTime.Now; var st = Stopwatch.StartNew(); int i = 0; try { TestRun result = null; using (context.StartSubProgress()) { for (i = 0; i < _commands.Count; i++) { context.ReportProgress(i, _commands.Count, "Running test '" + this.Name + "'..."); try { await _commands[i].Run(context); } catch (AssertionFailedException ex) { if (result == null) result = new TestRun() { Name = this.Name, Result = TestResult.Fail, Start = start, ErrorLine = i + 1, Message = ex.Message }; } } } if (result == null) return new TestRun() { Name = this.Name, Result = TestResult.Pass, ElapsedMilliseconds = st.ElapsedMilliseconds, Start = start }; result.ElapsedMilliseconds = st.ElapsedMilliseconds; return result; } catch (Exception ex) { return new TestRun() { Name = this.Name, Result = TestResult.Fail, ElapsedMilliseconds = st.ElapsedMilliseconds, Start = start, ErrorLine = i + 1, Message = ex.Message }; } finally { context.LastResult = null; } }
public async Task Run(TestContext context) { _results.Clear(); _output.Clear(); using (context.StartSubProgress()) { var start = DateTime.Now; var i = 0; var pos = 0; var totalCount = _init.Count + _tests.Count + _cleanup.Count; try { for (i = 0; i < _init.Count; i++) { context.ReportProgress(pos, totalCount, "Running initialization..."); await _init[i].Run(context); pos += 1; } } catch (Exception ex) { _results.Add(new TestRun() { Name = "* Init", Result = TestResult.Fail, Start = start, ErrorLine = i + 1, Message = ex.Message }); return; } for (i = 0; i < _tests.Count; i++) { context.ReportProgress(pos, totalCount, "Running test " + (i + 1) + "..."); _results.Add(await _tests[i].Run(context)); pos += 1; } try { for (i = 0; i < _cleanup.Count; i++) { context.ReportProgress(pos, totalCount, "Running cleanup..."); await _cleanup[i].Run(context); pos += 1; } } catch (Exception ex) { _results.Add(new TestRun() { Name = "* Cleanup", Result = TestResult.Fail, Start = start, ErrorLine = i + 1, Message = ex.Message }); return; } foreach (var kvp in context.Parameters) { _output.Add(new ParamAssign() { Name = kvp.Key, Value = kvp.Value }); } } }
public async Task <TestRun> Run(TestContext context) { var start = DateTime.Now; var st = Stopwatch.StartNew(); int i = 0; try { TestRun result = null; using (context.StartSubProgress()) { for (i = 0; i < _commands.Count; i++) { context.ReportProgress(i, _commands.Count, "Running test '" + this.Name + "'..."); try { await _commands[i].Run(context); } catch (AssertionFailedException ex) { if (result == null) { result = new TestRun() { Name = this.Name, Result = TestResult.Fail, Start = start, ErrorLine = i + 1, Message = ex.Message } } ; } } } if (result == null) { return new TestRun() { Name = this.Name, Result = TestResult.Pass, ElapsedMilliseconds = st.ElapsedMilliseconds, Start = start } } ; result.ElapsedMilliseconds = st.ElapsedMilliseconds; return(result); } catch (Exception ex) { return(new TestRun() { Name = this.Name, Result = TestResult.Fail, ElapsedMilliseconds = st.ElapsedMilliseconds, Start = start, ErrorLine = i + 1, Message = ex.Message }); } finally { context.LastResult = null; } }