public void RepeatWhileError(Verdict targetVerdict, RepeatStep.RepeatStepAction action) { var step = new PassThirdTime(); BreakConditionProperty.SetBreakCondition(step, BreakCondition.BreakOnFail); var rpt = new RepeatStep() { Action = action, TargetVerdict = targetVerdict, Retry = true }; rpt.TargetStep = rpt; // target self. The Repeat Loop will inherit the verdict. rpt.ChildTestSteps.Add(step); var plan = new TestPlan(); plan.ChildTestSteps.Add(rpt); var run = plan.Execute(); Assert.AreEqual(Verdict.Pass, run.Verdict); Assert.AreEqual(3, step.Iterations); }
public void RepeatUntilPass([Values(true, false)] bool retry) { var step = new PassThirdTime(); BreakConditionProperty.SetBreakCondition(step, BreakCondition.BreakOnFail); var rpt = new RepeatStep() { Action = RepeatStep.RepeatStepAction.Until, TargetStep = step, TargetVerdict = Verdict.Pass, Retry = retry }; rpt.ChildTestSteps.Add(step); var plan = new TestPlan(); plan.ChildTestSteps.Add(rpt); var run = plan.Execute(); if (retry) { Assert.AreEqual(Verdict.Pass, run.Verdict); Assert.AreEqual(3, step.Iterations); } else { // break condition reached -> Error verdict. Assert.AreEqual(Verdict.Error, run.Verdict); Assert.AreEqual(1, step.Iterations); } }
public void TestNameFormat2() { var plan = new TestPlan(); var repeat = new RepeatStep { Count = 10, Action = RepeatStep.RepeatStepAction.Fixed_Count }; repeat.Name = "Repeat : {Iteration}"; plan.ChildTestSteps.Add(repeat); var logStep = new LogStep(); repeat.ChildTestSteps.Add(logStep); var log = new TestTraceListener(); Log.AddListener(log); var run = plan.Execute(); Assert.AreEqual(Verdict.NotSet, run.Verdict); Log.RemoveListener(log); var thelog = log.GetLog(); for (int i = 0; i < repeat.Count; i++) { var str = string.Format("Repeat : {0} of {1}", i, repeat.Count); Assert.IsTrue(thelog.Contains(str)); } }
public void RunLoop() { TestPlan testplan = new TestPlan(); var grandParent = new RepeatStep(); uint loopCount = 7; grandParent.Count = loopCount; grandParent.Action = RepeatStep.RepeatStepAction.Fixed_Count; testplan.Steps.Add(grandParent); var parent = new WithEvents(); grandParent.ChildTestSteps.Add(parent); testplan.BreakOffered += _testplan_TestStepPaused; _pausedDetectedCount = 0; _startingDetectedCount = 0; testplan.Execute(); //We will actually have loopCount + 1 starts. // We get a start for each of the loops around "withevents steps", plus one for the outer loop "FixedCountLoop" step Assert.AreEqual(loopCount + 1, _startingDetectedCount, "StartingDetectedCount"); //Since fixed count loop does NOT have a pause, it will not count in the pause count. Assert.AreEqual(loopCount, _pausedDetectedCount, "PausedDetectedCount"); }
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 TestPlanReferenceNameTest() { var step = new DelayStep(); var testPlanReference = new TestPlanReference(); var repeatStep = new RepeatStep(); repeatStep.ChildTestSteps.Add(testPlanReference); var plan = new TestPlan(); plan.ChildTestSteps.Add(step); plan.ChildTestSteps.Add(repeatStep); var mem = AnnotationCollection.Annotate(repeatStep).Get <IMembersAnnotation>().Members .FirstOrDefault(x => x.Get <IMemberAnnotation>().Member.Name == nameof(RepeatStep.TargetStep)); var avail = mem.Get <IAvailableValuesAnnotationProxy>().AvailableValues; var availStrings = avail.Select(x => x.Get <IStringReadOnlyValueAnnotation>().Value).ToArray(); Assert.IsTrue(availStrings.Contains(step.GetFormattedName())); Assert.IsTrue(availStrings.Contains(testPlanReference.GetFormattedName())); }
public void SweepRaceBug() { // test that validation rules can be checked while the test plan is running // without causing an error. The validation rules does not need to do actual validation // but since SweepLoop and SweepLoopRange modifies its child steps this could cause an error // as shown by SweepRaceBugCheckStep and SweepRaceBugStep. var plan = new TestPlan(); var repeat = new RepeatStep { Count = 10, Action = RepeatStep.RepeatStepAction.Fixed_Count }; var loop = new SweepLoop(); repeat.ChildTestSteps.Add(loop); loop.ChildTestSteps.Add(new SweepRaceBugStep() { }); loop.ChildTestSteps.Add(new SweepRaceBugCheckStep() { }); var steptype = TypeData.FromType(typeof(SweepRaceBugStep)); var member = steptype.GetMember(nameof(SweepRaceBugStep.Frequency)); var member2 = TypeData.FromType(typeof(SweepRaceBugCheckStep)).GetMember(nameof(SweepRaceBugCheckStep.Frequency2)); var lst = new List <SweepParam>(); double[] values = new double[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; lst.Add(new SweepParam(new[] { member }, values.Cast <object>().ToArray())); lst.Add(new SweepParam(new[] { member2 }, values.Cast <object>().ToArray())); loop.SweepParameters = lst; var loopRange = new SweepLoopRange(); loopRange.SweepStart = 1; loopRange.SweepEnd = 10; loopRange.SweepPoints = 10; loopRange.ChildTestSteps.Add(new SweepRaceBugStep() { }); loopRange.ChildTestSteps.Add(new SweepRaceBugCheckStep() { }); loopRange.SweepProperties = new List <IMemberData> { member, member2 }; var repeat2 = new RepeatStep { Count = 10, Action = RepeatStep.RepeatStepAction.Fixed_Count }; repeat2.ChildTestSteps.Add(loopRange); var parallel = new ParallelStep(); plan.ChildTestSteps.Add(parallel); parallel.ChildTestSteps.Add(repeat); parallel.ChildTestSteps.Add(repeat2); TestPlanRun run = null; TapThread.Start(() => run = plan.Execute()); TapThread.Start(() => { while (run == null) { loopRange.Error.ToList(); } }); while (run == null) { loop.Error.ToList(); } Assert.AreEqual(Verdict.NotSet, run.Verdict); }