示例#1
0
            public void OneTimeTearDown()
            {
                var scenarios = BDTestUtil.GetScenarios().Where(x => x.GetScenarioText() == "RetryOnStoryTests").ToList();

                Assert.That(scenarios.Count, Is.EqualTo(1));
                Assert.That(scenarios.First().Status, Is.EqualTo(Status.Passed));
            }
示例#2
0
        public static string GetTestJsonData(BDTestRunDescriptor bdTestRunDescriptor)
        {
            var scenarios = BDTestUtil.GetScenarios();

            var testTimer = GetTestTimer(scenarios);

            var dataToOutput = new BDTestOutputModel
            {
                Id          = BDTestUtil.GetCurrentReportId,
                Environment = bdTestRunDescriptor?.Environment ?? BDTestSettings.Environment,
                Tag         = bdTestRunDescriptor?.Tag ?? BDTestSettings.Tag,
                BranchName  = bdTestRunDescriptor?.BranchName ?? BDTestSettings.BranchName,
                MachineName = Environment.MachineName,
                Scenarios   = scenarios,
                TestTimer   = testTimer,
                NotRun      = BDTestUtil.GetNotRunScenarios(),
                Version     = BDTestVersionHelper.CurrentVersion
            };

            var settings = new JsonSerializerSettings
            {
                PreserveReferencesHandling = PreserveReferencesHandling.Objects
            };

            return(JsonConvert.SerializeObject(dataToOutput, Formatting.Indented, settings));
        }
示例#3
0
        public void ThrowsExceptionOnThen(Type exceptionType, Status status)
        {
            try
            {
                When(() => Console.WriteLine("my test has an exception"))
                .Then(() => Console.WriteLine("the exception should be serialized to the json output"))
                .And(() => Console.WriteLine("the step is marked as failed"))
                .And(() => ThrowException(exceptionType))
                .And(() => Console.WriteLine("subsequent steps are inconclusive"))
                .And(() => Console.WriteLine("Previous steps should be marked as passed"))
                .BDTest();

                Assert.Fail("An exception should be thrown to stop us getting here!");
            }
            catch
            {
                var scenario = BDTestUtil.GetScenarios().First();

                Assert.That(scenario.Steps[3].Exception.Message.Contains("BDTest Exception!"));

                Assert.That(scenario.Steps[0].Status, Is.EqualTo(Status.Passed));
                Assert.That(scenario.Steps[1].Status, Is.EqualTo(Status.Passed));
                Assert.That(scenario.Steps[2].Status, Is.EqualTo(Status.Passed));
                Assert.That(scenario.Steps[3].Status, Is.EqualTo(status));
                Assert.That(scenario.Steps[4].Status, Is.EqualTo(Status.Inconclusive));
                Assert.That(scenario.Steps[5].Status, Is.EqualTo(Status.Inconclusive));

                Assert.That(scenario.Status, Is.EqualTo(status));

                Assert.That(
                    JsonHelper.GetTestDynamicJsonObject().SelectToken("$.Scenarios[0].Steps[3].Exception")
                    .ToString().Contains("BDTest Exception!"));

                Assert.That(
                    JsonHelper.GetTestDynamicJsonObject().SelectToken("$.Scenarios[0].Steps[0].Status").ToString(),
                    Is.EqualTo("Passed"));
                Assert.That(
                    JsonHelper.GetTestDynamicJsonObject().SelectToken("$.Scenarios[0].Steps[1].Status").ToString(),
                    Is.EqualTo("Passed"));
                Assert.That(
                    JsonHelper.GetTestDynamicJsonObject().SelectToken("$.Scenarios[0].Steps[2].Status").ToString(),
                    Is.EqualTo("Passed"));
                Assert.That(
                    JsonHelper.GetTestDynamicJsonObject().SelectToken("$.Scenarios[0].Steps[3].Status").ToString(),
                    Is.EqualTo(status.ToString()));
                Assert.That(
                    JsonHelper.GetTestDynamicJsonObject().SelectToken("$.Scenarios[0].Steps[4].Status").ToString(),
                    Is.EqualTo("Inconclusive"));
                Assert.That(
                    JsonHelper.GetTestDynamicJsonObject().SelectToken("$.Scenarios[0].Steps[5].Status").ToString(),
                    Is.EqualTo("Inconclusive"));

                Assert.That(JsonHelper.GetTestDynamicJsonObject().SelectToken("$.Scenarios[0].Status").ToString(),
                            Is.EqualTo(status.ToString()));
            }
        }
示例#4
0
        public void NUNitSuccessException()
        {
            try
            {
                Given(() => Console.WriteLine("NUnit throws a success exception"))
                .When(() => Assert.Pass())
                .Then(() => Console.WriteLine("the test has passed"))
                .BDTest();

                Assert.Fail("An exception should be thrown to stop us getting here!");
            }
            catch (SuccessException)
            {
                var scenario = BDTestUtil.GetScenarios().First();
                Assert.That(scenario.Status, Is.EqualTo(Status.Passed));
            }
        }
示例#5
0
        public void NUNitIgnoreException()
        {
            try
            {
                Given(() => Console.WriteLine("NUnit throws an ignore exception"))
                .When(() => Assert.Ignore())
                .Then(() => Console.WriteLine("the test is ignored"))
                .BDTest();

                Assert.Fail("An exception should be thrown to stop us getting here!");
            }
            catch (IgnoreException)
            {
                var scenario = BDTestUtil.GetScenarios().First();

                Assert.That(scenario.Status, Is.EqualTo(Status.Inconclusive));
            }
        }
示例#6
0
        public void CustomException()
        {
            BDTestSettings.CustomExceptionSettings.SuccessExceptionTypes.Add(typeof(MyAllowedException));

            try
            {
                Given(() => Console.WriteLine("NUnit throws a success exception"))
                .When(() => ThrowException())
                .Then(() => Console.WriteLine("the test has passed"))
                .BDTest();

                Assert.Fail("An exception should be thrown to stop us getting here!");
            }
            catch (MyAllowedException)
            {
                var scenario = BDTestUtil.GetScenarios().First();
                Assert.That(scenario.Status, Is.EqualTo(Status.Passed));
            }
        }
示例#7
0
        public void CustomIgnoreException()
        {
            BDTestSettings.CustomExceptionSettings.InconclusiveExceptionTypes.Add(typeof(MyCustomIgnoreException));
            try
            {
                Given(() => Console.WriteLine("NUnit throws an ignore exception"))
                .When(() => ThrowException())
                .Then(() => Console.WriteLine("the test is ignored"))
                .BDTest();

                Assert.Fail("An exception should be thrown to stop us getting here!");
            }
            catch (MyCustomIgnoreException)
            {
                var scenario = BDTestUtil.GetScenarios().First();

                Assert.That(scenario.Status, Is.EqualTo(Status.Inconclusive));
            }
        }
示例#8
0
        public void CanDeserializeJsonResultsSuccessfully()
        {
            When(() => Console.WriteLine("A persistent json file is written")).WithStepText(() => "I write custom when step text")
            .Then(() => CustomStep("1", "2"))
            .BDTest();

            var inMemoryScenario = BDTestUtil.GetScenarios().Single();

            var json    = BDTestJsonHelper.GetTestJsonData();
            var jObject = JObject.Load(new JsonTextReader(new StringReader(json)));

            var scenarios = JsonConvert.DeserializeObject <List <Scenario> >(jObject.GetValue("Scenarios").ToString());

            Assert.That(scenarios, Is.Not.Null);
            Assert.That(scenarios.Count, Is.EqualTo(1));

            var deserializedScenario = scenarios.First();

            Assert.That(deserializedScenario.Steps[0].StepText, Is.EqualTo("When I write custom when step text"));
            Assert.That(deserializedScenario.Steps[1].StepText, Is.EqualTo("Then 1 2"));

            var compareLogic = new CompareLogic
            {
                Config = new ComparisonConfig
                {
                    MaxDifferences = int.MaxValue,
                    // The below are runtime only, and so we don't serialize.
                    MembersToIgnore =
                    {
                        nameof(Scenario.BdTestBaseClass)
                    }
                }
            };

            var comparisonResult = compareLogic.Compare(inMemoryScenario, deserializedScenario);

            Assert.That(comparisonResult.AreEqual, Is.True);
        }
示例#9
0
 public static void ResetData()
 {
     ClearedScenarios.AddRange(BDTestUtil.GetScenarios());
     BDTestUtil.ClearScenarios();
 }