How to use async_before_all_example_spec class of NSpec.Tests.WhenRunningSpecs.BeforeAndAfter package

Best NSpec code snippet using NSpec.Tests.WhenRunningSpecs.BeforeAndAfter.async_before_all_example_spec

Run NSpec automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

async_when_there_are_no_specs.cs

Source: async_when_there_are_no_specs.cs Github

copy
1using FluentAssertions;
2using NUnit.Framework;
3using System.Threading.Tasks;
4
5namespace NSpec.Tests.WhenRunningSpecs.BeforeAndAfter
6{
7    [TestFixture]
8    [Category("Async")]
9    public class async_when_there_are_no_specs : when_running_specs
10    {
11        [SetUp]
12        public void setup()
13        {
14            sequence_spec.sequence = "";
15        }
16
17        class async_before_all_example_spec : sequence_spec
18        {
19            async Task before_all()
20            {
21                await Task.Run(() => sequence = "executed");
22            }
23        }
24
25        [Test]
26        public void async_before_all_is_not_executed()
27        {
28            Run(typeof(async_before_all_example_spec));
29
30            sequence_spec.sequence.Should().Be("");
31        }
32
33        class async_before_each_example_spec : sequence_spec
34        {
35            async Task before_each()
36            {
37                await Task.Run(() => sequence = "executed");
38            }
39        }
40
41        [Test]
42        public void async_before_each_is_not_executed()
43        {
44            Run(typeof(async_before_each_example_spec));
45
46            sequence_spec.sequence.Should().Be("");
47        }
48
49        class after_each_example_spec : sequence_spec
50        {
51            async Task after_each()
52            {
53                await Task.Run(() => sequence += "executed");
54            }
55        }
56
57        [Test]
58        public void after_each_is_not_executed()
59        {
60            Run(typeof (after_each_example_spec));
61
62            sequence_spec.sequence.Should().Be("");
63        }
64
65        class after_all_example_spec : sequence_spec
66        {
67            async Task after_all()
68            {
69                await Task.Run(() => sequence += "executed");
70            }
71        }
72
73        [Test]
74        public void after_all_is_not_executed()
75        {
76            Run(typeof (after_all_example_spec));
77
78            sequence_spec.sequence.Should().Be("");
79        }
80    }
81}
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

Run Selenium Automation Tests on LambdaTest Cloud Grid

Trigger Selenium automation tests on a cloud-based Grid of 3000+ real browsers and operating systems.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)