Bull
Bull

Reputation: 701

Specflow test for export to excel

I am currently implementing an export to excel feature in .net 4.5 using infragistics.excel. So when a user clicks the export button on a web page, an excel file (containing some formatted data is downloaded to his machine)

Is there an easy way to test this using specflow. Can anyone who has done something like this before share how best this could be tested in specflow.

Thanks!

Upvotes: 0

Views: 1450

Answers (1)

AlSki
AlSki

Reputation: 6961

What are you looking for here?

Specflow is a great tool for working with "Specification By Example". So first we need a simple example for our specification, maybe something like

Feature: Export to Excel
As a user
I want to Export my applications state
So that I can load it into Excel

Scenario: Export empty state
Given a default state
When I export
Then my export is a blank sheet

If @Lunivore were here now then she would definitely be telling you that BDD is all about having the conversations with your business users to define exactly what they want and that process of discovery is where most of the value in BDD comes from.

You will notice that I haven't spoken about concepts such as files, or browsers or any specific to a particular domain (See Who's domain is it anyway), which allows me to test at whatever level I choose, so if I'm using MVC, I don't need to worry about the view and can instead focus on making sure my controllers correctly work with my models, rather than worrying about how it looks.

However the way you have phrased the question, makes me think you want to use SpecFlow to work at a higher level, that you want to call Selenium to control your browser to click the button and return the file. If that is the case, you are going to need to ask others how to do that.

Also,

One thing people commonly overlook with BDD/Specification by example/Specflow is that isn't mutually exclusive to TDD, in fact you will find you get better results by wrapping several TDD Red Green refactor cycles up in a single BDD cycle, basically you use the business example to shape your development of unit tests, just as you use your unit tests to shape your code.

Upvotes: 1

Related Questions