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...
My name is Ben and I am a software developer from Sussex, England. The purpose of this blog is to keep a record of technologies I utilise throughout my career as a software developer. I believe that not only will this further cement my understanding of these technologies, but also serve as a useful personal resource for future work.