public void EngineInheritedConditions(Verdict verdictOutput, EngineSettings.AbortTestPlanType abortTestPlanType, int runCount) { Verdict finalVerdict = verdictOutput; var prev = EngineSettings.Current.AbortTestPlan; try { EngineSettings.Current.AbortTestPlan = abortTestPlanType; var l = new PlanRunCollectorListener(); TestPlan plan = new TestPlan(); var verdict = new VerdictStep { VerdictOutput = verdictOutput }; BreakConditionProperty.SetBreakCondition(verdict, BreakCondition.Inherit); var verdict2 = new VerdictStep { VerdictOutput = Verdict.Pass }; plan.Steps.Add(verdict); plan.Steps.Add(verdict2); var run = plan.Execute(new[] { l }); Assert.AreEqual(finalVerdict, run.Verdict); Assert.AreEqual(runCount, l.StepRuns.Count); Assert.AreEqual(BreakCondition.Inherit, BreakConditionProperty.GetBreakCondition(verdict2)); } finally { EngineSettings.Current.AbortTestPlan = prev; } }
public void RunCompositeStartTime() { PlanRunCollectorListener listener = new PlanRunCollectorListener(); ResultSettings.Current.Add(listener); TestTraceListener trace = new TestTraceListener(); Log.AddListener(trace); TestPlan target = getTestTestPlan(); target.Open(); target.Execute(); listener.StepRuns.Clear(); target.Execute(); target.Close(); Log.RemoveListener(trace); ResultSettings.Current.Remove(listener); Assert.AreEqual(2, listener.PlanRuns.Select(run => run.StartTimeStamp).Distinct().Count()); Assert.AreEqual(1, listener.StepRuns.Count()); }
public void TestStepBreakOnError(Verdict verdictOutput, object _condition) { // _condition arg cannot be a BreakCondition as BreakCondition is not public. BreakCondition condition = (BreakCondition)_condition; var l = new PlanRunCollectorListener(); TestPlan plan = new TestPlan(); var verdict = new VerdictStep { VerdictOutput = verdictOutput }; BreakConditionProperty.SetBreakCondition(verdict, condition); var verdict2 = new VerdictStep { VerdictOutput = Verdict.Pass }; plan.Steps.Add(verdict); plan.Steps.Add(verdict2); var run = plan.Execute(new[] { l }); Assert.AreEqual(verdictOutput, run.Verdict); Assert.AreEqual(1, l.StepRuns.Count); Assert.AreEqual(BreakCondition.Inherit, BreakConditionProperty.GetBreakCondition(verdict2)); var log = l.LogString; Assert.IsTrue(log.Contains("Break issued from")); }
public void TestResourceReference() { // Loop seems to provoke a race condition in test plan execution for (int i = 0; i < 10; i++) { EngineSettings.Current.ToString(); var step = new OpenTap.Plugins.BasicSteps.SweepLoop(); var theDuts = Enumerable.Range(0, 10).Select(number => new IsOpenedDut()).ToArray(); var otherdut = new IsOpenedDut(); step.ChildTestSteps.Add(new IsOpenUsedTestStep() { Resource = new IsOpenedDut(), Resource2 = otherdut, Resource3 = new [] { new IsOpenedDut() } }); step.SweepParameters.Add(new OpenTap.Plugins.BasicSteps.SweepParam(new IMemberData[] { TypeData.FromType(typeof(IsOpenUsedTestStep)).GetMember("Resource") }, theDuts)); var plan = new TestPlan(); plan.PrintTestPlanRunSummary = true; plan.ChildTestSteps.Add(step); var rlistener = new PlanRunCollectorListener(); var planRun = plan.Execute(new IResultListener[] { rlistener }); Assert.AreEqual(theDuts.Length + 1, rlistener.StepRuns.Count); Assert.IsTrue(planRun.Verdict == Verdict.NotSet); Assert.IsTrue(theDuts.All(dut => dut.IsClosed && dut.IsOpened && dut.IsUsed)); } }
public void TestPlanBreakConditions() { var plan = new TestPlan(); var errorStep = new VerdictStep() { VerdictOutput = Verdict.Error }; var failStep = new VerdictStep() { VerdictOutput = Verdict.Fail }; var inconclusiveStep = new VerdictStep() { VerdictOutput = Verdict.Inconclusive }; var passStep = new VerdictStep() { VerdictOutput = Verdict.Pass }; plan.Steps.Add(errorStep); plan.Steps.Add(failStep); plan.Steps.Add(inconclusiveStep); plan.Steps.Add(passStep); var defaultValue = BreakConditionProperty.GetBreakCondition(plan); Assert.AreEqual(BreakCondition.Inherit, defaultValue); // break on fail, this means that 'passStep' will not get executed BreakConditionProperty.SetBreakCondition(plan, BreakCondition.BreakOnError); var col = new PlanRunCollectorListener(); plan.Execute(new [] { col }); Assert.AreEqual(1, col.StepRuns.Count); BreakConditionProperty.SetBreakCondition(plan, BreakCondition.BreakOnFail); col = new PlanRunCollectorListener(); plan.Execute(new [] { col }); Assert.AreEqual(2, col.StepRuns.Count); BreakConditionProperty.SetBreakCondition(plan, BreakCondition.BreakOnInconclusive); col = new PlanRunCollectorListener(); plan.Execute(new [] { col }); Assert.AreEqual(3, col.StepRuns.Count); BreakConditionProperty.SetBreakCondition(plan, 0); col = new PlanRunCollectorListener(); plan.Execute(new [] { col }); Assert.AreEqual(4, col.StepRuns.Count); }
public void RunRepeat() { // plan: // repeat1 (count 3) // repeat2 (count 3) // setVer - sets verdict to pass // checkif - breaks repeat 2 // setVer2 - is never executed. // total number of step runs: // repeat1: 1 // repeat2: 3 // setVer: 3 // checkif: 3 // setVer2: 0 // Total: 10 var rlistener = new PlanRunCollectorListener(); var repeat1 = new RepeatStep { Action = RepeatStep.RepeatStepAction.Fixed_Count, Count = 3 }; var repeat2 = new RepeatStep { Action = RepeatStep.RepeatStepAction.Fixed_Count, Count = 3 }; var setVer = new TestTestSteps.VerdictStep() { VerdictOutput = Verdict.Pass }; var checkif = new IfStep() { Action = IfStep.IfStepAction.BreakLoop, TargetVerdict = setVer.VerdictOutput }; var setVer2 = new TestTestSteps.VerdictStep(); // this one is never executed. repeat2.ChildTestSteps.AddRange(new ITestStep[] { setVer, checkif, setVer2 }); repeat1.ChildTestSteps.Add(repeat2); var plan = new TestPlan(); plan.ChildTestSteps.Add(repeat1); checkif.InputVerdict.Step = setVer; checkif.InputVerdict.Property = TypeData.FromType(typeof(TestStep)).GetMember(nameof(TestStep.Verdict)); var planrun = plan.Execute(new[] { rlistener }); Assert.AreEqual(10, rlistener.StepRuns.Count); Assert.AreEqual(5, planrun.StepsWithPrePlanRun.Count); }
public void RunCompositeMetaData() { PlanRunCollectorListener listener = new PlanRunCollectorListener(); ResultSettings.Current.Add(listener); TestTraceListener trace = new TestTraceListener(); Log.AddListener(trace); TestPlan target = getTestTestPlan(); TestPlanRun run = target.Execute(); Log.RemoveListener(trace); ResultSettings.Current.Remove(listener); Assert.IsTrue(run.Parameters.Any(par => par.Value.ToString() == "Test Instrument")); Assert.IsFalse(run.Parameters.Any(par => par.Name == "Comment")); }
public void RunCompositeMetaData2() { PlanRunCollectorListener listener = new PlanRunCollectorListener(); ResultSettings.Current.Add(listener); TestTraceListener trace = new TestTraceListener(); Log.AddListener(trace); TestPlan target = getTestTestPlan(); target.Open(); target.Execute(); target.Execute(); target.Close(); Log.RemoveListener(trace); ResultSettings.Current.Remove(listener); Assert.IsTrue(listener.PlanRuns.First().Parameters.Any(par => par.Value.ToString() == "Test Instrument")); Assert.AreEqual(1, listener.PlanRuns.Last().Parameters.Count(par => par.Value.ToString() == "Test Instrument")); }
public void RunCompositeAddInstrumentAfterOpen() { PlanRunCollectorListener listener = new PlanRunCollectorListener(); ResultSettings.Current.Add(listener); TestTraceListener trace = new TestTraceListener(); Log.AddListener(trace); TestPlan target = getTestTestPlan(); target.Open(); TestInstrument instr = InstrumentSettings.Current.FirstOrDefault(i => i is TestInstrument && (i as TestInstrument).Name.EndsWith("2")) as TestInstrument; if (instr == null) { instr = new TestInstrument { Name = "Test Instrument 2" }; InstrumentSettings.Current.Add(instr); } (target.Steps[0] as TestTestStep).Instr = instr; target.Execute(); listener.StepRuns.Clear(); target.Execute(); target.Close(); Log.RemoveListener(trace); ResultSettings.Current.Remove(listener); Assert.AreEqual(2, listener.PlanRuns.Select(run => run.StartTimeStamp).Distinct().Count()); Assert.AreEqual(1, listener.StepRuns.Count()); }
public void RunSweepWithInterruptions(bool loopRange) { IEnumerable <int> check; var tp = new TestPlan(); TestStep sweep; if (loopRange) { var sweepRange = new SweepLoopRange(); sweepRange.SweepStart = 10; sweepRange.SweepEnd = 30; sweepRange.SweepStep = 1; sweepRange.SweepProperties = new List <IMemberData>() { TypeData.FromType(typeof(SweepTestStep)).GetMember("SweepProp") }; sweep = sweepRange; check = Enumerable.Range(10, (int)(sweepRange.SweepEnd - sweepRange.SweepStart + 1)); } else { check = Enumerable.Range(10, 20); var sweepRange = new SweepLoop(); var lst = new List <SweepParam>(); lst.Add(new SweepParam(new[] { TypeData.FromType(typeof(SweepTestStep)).GetMember("SweepProp") }, check.Cast <object>().ToArray())); sweepRange.SweepParameters = lst; sweep = sweepRange; } var step = new SweepTestStep(); tp.ChildTestSteps.Add(sweep); sweep.ChildTestSteps.Add(step); var rlistener = new PlanRunCollectorListener() { CollectResults = true }; bool done = false; void interruptOperations() { // this is to reproduce an error previously happening when the // SweepLoopRange.Error value was getted. // this would have changed the value of SweepProp intermiddently. while (!done) { // so bother as much as possible... var error2 = sweep.Error; } } var trd = new Thread(interruptOperations); trd.Start(); var result = tp.Execute(new[] { rlistener }); done = true; trd.Join(); var results = rlistener.Results.Select(x => (int)x.Result.Columns[0].Data.GetValue(0)).ToArray(); Assert.IsTrue(results.SequenceEqual(check)); }