Driving Canopy Tests with TypeProviders

One of the most amazing features in F# is Type Providers. They allow you to access data sources in incredibly easy ways. You can query data from databases, read data from CSV files, or consume JSON data from an API. I’m not going to go into depth here on Type Providers, but if you are unfamiliar with them, you should go check them out.

Often times when I am writing Canopy tests, I want to validate that some data from the database is being displayed on the screen. So what I need to do is get the data from the database and use it in a Canopy test.

To use a TypeProvider for data retrieval, the first thing you will need to do is include the FSharp.Data.TypeProviders assembly from NuGet. After that, this is all of the code that you need to start getting data.

That is it. There is nothing else to do. You have strongly typed classes based on the data in your data source.

In this example, I am using the data from the Crisis Checkin database. Now that I have queried the list of disasters, I could easily right a test that ensures that all of the disasters are listed on the site. Or I could right tests that ensure that volunteers can register for disasters that are currently open.

Driving tests from the database allows the tests to use relevant information that stays up to date with the web application under test. There is no need to maintain a separate data source for the test data, it can easily directly from the database.

August 29, 2016 |
Tags : Canopy F#

Comments Section

Feel free to comment on the post but keep it clean and on topic.

comments powered by Disqus

About Me

Eric Potter My name is Eric Potter. I have an amazing wife and 5 wonderful children. I am a Microsoft MVP for .Net. I am a software architect for Aptera Software in Ft. Wayne Indiana and an adjunct professor for Indiana Tech. I am a humble toolsmith.

Microsoft MVP Award