Skip to main content

Posts

Showing posts from January, 2018

Behaviour-driven development (BDD) with Specflow - Part 2

This post is the second in the series of posts regarding implementing SpecFlow for unit tests within BDD. This section looks at how tests can be written to check that the correct exceptions are thrown under certain conditions. An understanding of  Behaviour-driven development (BDD) with Specflow - Part 1 and Using the Mediatr pipeline with Fluent Validation  is assumed. Firstly, two steps must be written. A step to add the user without a name and a second to return the error message. Step to add invalid user The user data is passed in as a dynamic, then the properties are assigned to an AddUserModel , which is what is passed to the AddUserRequest . The AddUser  method on the administration engine is called and the exception remembered in the test context. Note that this exact step could also be used in a test to check that a user can not be added without an age assigned. Step to verify exception The exception is recalled from the text context and verified...

Behaviour-driven development (BDD) with Specflow - Part 1

This post describes how to utilise SpecFlow to write unit tests that implement behaviour-driven development (BDD). Details on the BDD can be found on this wikipedia page. SpecFlow is simple to install through the Nuget package manager, more information can be found on the SpecFlow site . SpecFlow tests comprise of two main elements: features and steps. In feature files, scenarios are written which together test all the behaviours of the feature. Each test will call methods in a step file, which is where the C# code resides and the actual. In this blog post, we just look at a couple of very simple examples. In the future, there will be posts which go into more detail about the power of SpecFlow. Below is an example feature file for getting all users from a database, titled Get all users . At the top, the feature is defined subsequently a bit more detail is given. This is a suite of tests that will prescribe the behaviour for getting all users. The first scenario details the...