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 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 ScopedInputAnnotationWithSweepTestSerialized() { var plan = new TestPlan(); var sweepStep = new SweepParameterStep(); plan.Steps.Add(sweepStep); var verdictStep = new VerdictStep(); sweepStep.ChildTestSteps.Add(verdictStep); var ifStep = new IfStep(); sweepStep.ChildTestSteps.Add(ifStep); var member = TypeData.GetTypeData(ifStep).GetMember(nameof(IfStep.InputVerdict)); var parameterizedMember = member.Parameterize(sweepStep, ifStep, member.Name); var annotation = AnnotationCollection.Annotate(sweepStep); var memberAnnotation = annotation.GetMember(nameof(sweepStep.SweepValues)); var col = memberAnnotation.Get <ICollectionAnnotation>(); col.AnnotatedElements = new[] { col.NewElement() }; annotation.Write(); annotation.Read(); var sweepValuesMember = TypeData.GetTypeData(sweepStep).GetMember(nameof(sweepStep.SweepValues)); sweepValuesMember.Parameterize(plan, sweepStep, "SweepValues"); var planstr = plan.SerializeToString(); var plan2 = Utils.DeserializeFromString <TestPlan>(planstr); var ext = plan2.ExternalParameters.Get("SweepValues"); Assert.IsNotNull(ext); }
public void ScopedInputAnnotationWithSweepTest() { var sweepStep = new SweepParameterStep(); var verdictStep = new VerdictStep(); sweepStep.ChildTestSteps.Add(verdictStep); var ifStep = new IfStep(); sweepStep.ChildTestSteps.Add(ifStep); var member = TypeData.GetTypeData(ifStep).GetMember(nameof(IfStep.InputVerdict)); var parameterizedMember = member.Parameterize(sweepStep, ifStep, member.Name); var annotation = AnnotationCollection.Annotate(sweepStep); var memberAnnotation = annotation.GetMember(nameof(sweepStep.SweepValues)); var col = memberAnnotation.Get <ICollectionAnnotation>(); col.AnnotatedElements = new[] { col.NewElement() }; annotation.Write(); annotation.Read(); var member2Annotation = col.AnnotatedElements.FirstOrDefault().GetMember(parameterizedMember.Name); var avail = member2Annotation.Get <IAvailableValuesAnnotation>(); Assert.IsNotNull(avail); // available values: None, verdict from itself, verdict from SetVerdict. Assert.AreEqual(3, avail.AvailableValues.Cast <object>().Count()); var strings = avail.AvailableValues.Cast <object>().Select(x => x.ToString()).ToArray(); Assert.IsTrue(strings.Contains($"Verdict from {ifStep.GetFormattedName()}")); Assert.IsTrue(strings.Contains("None")); Assert.IsTrue(strings.Contains($"Verdict from {verdictStep.GetFormattedName()}")); }
public void ScopedInputAnnotationTest() { var seqStep = new SequenceStep(); var verdictStep = new VerdictStep(); seqStep.ChildTestSteps.Add(verdictStep); var ifStep = new IfStep(); seqStep.ChildTestSteps.Add(ifStep); var member = TypeData.GetTypeData(ifStep).GetMember(nameof(IfStep.InputVerdict)); var parameterizedMember = member.Parameterize(seqStep, ifStep, member.Name); var annotation = AnnotationCollection.Annotate(seqStep); var memberAnnotation = annotation.GetMember(parameterizedMember.Name); var avail = memberAnnotation.Get <IAvailableValuesAnnotation>(); Assert.IsNotNull(avail); // available values: None, verdict from itself, verdict from SetVerdict. Assert.AreEqual(3, avail.AvailableValues.Cast <object>().Count()); var strings = avail.AvailableValues.Cast <object>().Select(x => x.ToString()).ToArray(); Assert.IsTrue(strings.Contains($"Verdict from {ifStep.GetFormattedName()}")); Assert.IsTrue(strings.Contains("None")); Assert.IsTrue(strings.Contains($"Verdict from {verdictStep.GetFormattedName()}")); }
public void ContinueLoop() { var sequence = new SequenceStep(); var verdict1 = new VerdictStep { VerdictOutput = Verdict.Pass }; var ifstep = new IfStep() { Action = IfStep.IfStepAction.ContinueLoop, TargetVerdict = Verdict.Pass }; ifstep.InputVerdict.Property = TypeData.GetTypeData(verdict1).GetMember(nameof(VerdictStep.Verdict)); ifstep.InputVerdict.Step = verdict1; var verdict2 = new VerdictStep() { VerdictOutput = Verdict.Fail }; sequence.ChildTestSteps.Add(verdict1); sequence.ChildTestSteps.Add(ifstep); // instructed to skip the last verdict step sequence.ChildTestSteps.Add(verdict2); // if this step runs the plan will get the verdict 'fail'. var plan = new TestPlan(); plan.ChildTestSteps.Add(sequence); var run = plan.Execute(); Assert.AreEqual(Verdict.Pass, run.Verdict); }
public void TestNameFormat3() { var step = new VerdictStep() { Name = "Delay: {Resulting Verdict}", VerdictOutput = Verdict.NotSet }; var fmt = step.GetFormattedName(); Assert.AreEqual("Delay: Not Set", fmt); }
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 StepsCanOverrideVerdicts() { var plan = new TestPlan(); var stepCatch = new VerdictOverrideStep { OutputVerdict = Verdict.Pass }; var verdict = new VerdictStep { VerdictOutput = Verdict.Error }; plan.ChildTestSteps.Add(stepCatch); stepCatch.ChildTestSteps.Add(verdict); var run = plan.Execute(); Assert.AreEqual(Verdict.Pass, run.Verdict); }