How to use XitClass class of NSpec.Tests.WhenRunningSpecs package

Best NSpec code snippet using NSpec.Tests.WhenRunningSpecs.XitClass

Run NSpec automation tests on LambdaTest cloud grid

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

describe_todo.cs

Source: describe_todo.cs Github

copy
1using System;
2using System.Linq;
3using NSpec.Domain;
4using NUnit.Framework;
5using System.Threading.Tasks;
6using NSpec.Tests.WhenRunningSpecs.Exceptions;
7using FluentAssertions;
8
9namespace NSpec.Tests.WhenRunningSpecs
10{
11    [TestFixture]
12    [Category("RunningSpecs")]
13    [Category("Pending")]
14    public class using_xit : describe_todo
15    {
16        class XitClass : nspec
17        {
18            void method_level_context()
19            {
20                xit["should be pending"] = () => { executed = true; };
21            }
22
23            public static bool executed = false;
24        }
25
26        [Test]
27        public void example_should_be_pending()
28        {
29            var example = ExampleFrom(typeof(XitClass));
30
31            example.Pending.Should().BeTrue();
32        }
33
34        [Test]
35        public void example_should_not_throw()
36        {
37            var example = ExampleFrom(typeof(XitClass));
38
39            example.Exception.Should().BeNull();
40        }
41
42        [Test]
43        public void example_body_should_not_run()
44        {
45            XitClass.executed.Should().BeFalse();
46        }
47    }
48
49    [TestFixture]
50    [Category("RunningSpecs")]
51    [Category("Pending")]
52    [Category("Async")]
53    public class using_async_xit : describe_todo
54    {
55        class AsyncXitClass : nspec
56        {
57            void method_level_context()
58            {
59                xitAsync["should be pending"] = async () =>
60                {
61                    executed = true;
62                    await Task.Run(() => { });
63                };
64            }
65
66            public static bool executed = false;
67        }
68
69        [Test]
70        public void example_should_be_pending()
71        {
72            var example = ExampleFrom(typeof(AsyncXitClass));
73
74            example.HasRun.Should().BeTrue();
75
76            example.Pending.Should().BeTrue();
77        }
78
79        [Test]
80        public void example_should_not_throw()
81        {
82            var example = ExampleFrom(typeof(AsyncXitClass));
83
84            example.Exception.Should().BeNull();
85        }
86
87        [Test]
88        public void example_body_should_not_run()
89        {
90            AsyncXitClass.executed.Should().BeFalse();
91        }
92    }
93
94    [TestFixture]
95    [Category("RunningSpecs")]
96    [Category("Pending")]
97    [Category("Async")]
98    public class using_xit_with_async_lambda : describe_todo
99    {
100        class XitClassWithAsyncLambda : nspec
101        {
102            void method_level_context()
103            {
104                xit["should fail because xit is set to async lambda"] = async () =>
105                {
106                    executed = false;
107                    await Task.Run(() => { });
108                };
109
110                // No chance of error when (async) return value is explicitly typed. The following do not even compile:
111                /*
112                Func<Task> asyncTaggedDelegate = async () => await Task.Run(() => { });
113                Func<Task> asyncUntaggedDelegate = () => { return Task.Run(() => { }); };
114
115                xit["Should fail because xit is set to async tagged delegate"] = asyncTaggedDelegate;
116
117                xit["Should fail because xit is set to async untagged delegate"] = asyncUntaggedDelegate;
118                */
119            }
120
121            public static bool executed = false;
122        }
123
124        [Test]
125        public void example_should_be_pending()
126        {
127            var example = ExampleFrom(typeof(XitClassWithAsyncLambda));
128
129            example.HasRun.Should().BeTrue();
130
131            example.Pending.Should().BeTrue();
132        }
133
134        [Test]
135        public void example_should_throw()
136        {
137            var example = ExampleFrom(typeof(XitClassWithAsyncLambda));
138
139            example.Exception.Should().NotBeNull();
140
141            example.Exception.Should().BeOfType<AsyncMismatchException>();
142        }
143
144        [Test]
145        public void example_body_should_not_run()
146        {
147            XitClassWithAsyncLambda.executed.Should().BeFalse();
148        }
149    }
150
151    /*
152     * Test case on using async xit with sync lambda cannot be performed,
153     * as setting xitAsync to a sync lambda does not even compile:
154     *
155     * xitAsync["should fail because xit is set to sync lambda"] = () => { executed = false; };
156     *
157     */
158
159    [TestFixture]
160    [Category("RunningSpecs")]
161    [Category("Pending")]
162    public class using_todo : describe_todo
163    {
164        class TodoClass : nspec
165        {
166            void method_level_context()
167            {
168                it["should be pending"] = todo;
169            }
170        }
171
172        [Test]
173        public void example_should_be_pending()
174        {
175            var example = ExampleFrom(typeof(TodoClass));
176
177            example.HasRun.Should().BeTrue();
178
179            example.Pending.Should().BeTrue();
180        }
181    }
182
183    [TestFixture]
184    [Category("RunningSpecs")]
185    [Category("Pending")]
186    [Category("Async")]
187    public class using_async_todo : describe_todo
188    {
189        class AsyncTodoClass : nspec
190        {
191            void method_level_context()
192            {
193                itAsync["should be pending"] = todoAsync;
194            }
195        }
196
197        [Test]
198        public void example_should_be_pending()
199        {
200            var example = ExampleFrom(typeof(AsyncTodoClass));
201
202            example.HasRun.Should().BeTrue();
203
204            example.Pending.Should().BeTrue();
205        }
206    }
207
208    [TestFixture]
209    [Category("RunningSpecs")]
210    [Category("Pending")]
211    public class using_todo_with_throwing_before_all : describe_todo
212    {
213        class TodoClass : nspec
214        {
215            void method_level_context()
216            {
217                beforeAll = () => { throw new KnownException(); };
218
219                it["should be pending"] = todo;
220            }
221        }
222
223        [Test]
224        public void example_should_be_pending()
225        {
226            var example = ExampleFrom(typeof(TodoClass));
227
228            example.HasRun.Should().BeTrue();
229
230            example.Pending.Should().BeTrue();
231        }
232
233        [Test]
234        public void example_should_not_throw()
235        {
236            var example = ExampleFrom(typeof(TodoClass));
237
238            example.Exception.Should().BeNull();
239        }
240    }
241
242    [TestFixture]
243    [Category("RunningSpecs")]
244    [Category("Pending")]
245    public class using_todo_with_throwing_before : describe_todo
246    {
247        class TodoClass : nspec
248        {
249            void method_level_context()
250            {
251                before = () => { throw new KnownException(); };
252
253                it["should be pending"] = todo;
254            }
255        }
256
257        [Test]
258        public void example_should_be_pending()
259        {
260            var example = ExampleFrom(typeof(TodoClass));
261
262            example.HasRun.Should().BeTrue();
263
264            example.Pending.Should().BeTrue();
265        }
266
267        [Test]
268        public void example_should_not_throw()
269        {
270            var example = ExampleFrom(typeof(TodoClass));
271
272            example.Exception.Should().BeNull();
273        }
274    }
275
276    [TestFixture]
277    [Category("RunningSpecs")]
278    [Category("Pending")]
279    public class using_todo_with_throwing_act : describe_todo
280    {
281        class TodoClass : nspec
282        {
283            void method_level_context()
284            {
285                act = () => { throw new KnownException(); };
286
287                it["should be pending"] = todo;
288            }
289        }
290
291        [Test]
292        public void example_should_be_pending()
293        {
294            var example = ExampleFrom(typeof(TodoClass));
295
296            example.HasRun.Should().BeTrue();
297
298            example.Pending.Should().BeTrue();
299        }
300
301        [Test]
302        public void example_should_not_throw()
303        {
304            var example = ExampleFrom(typeof(TodoClass));
305
306            example.Exception.Should().BeNull();
307        }
308    }
309
310    public class describe_todo : when_running_specs
311    {
312        protected ExampleBase ExampleFrom(Type type)
313        {
314            Run(type);
315
316            return classContext.AllExamples().First();
317        }
318    }
319}
320
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)