4

I have already spending a lot of time googling for some solution but I'm helpless !

I got an MVC application and I'm trying to do "integration testing" for my Views using Coypu and SpecFlow. But I don't know how I should manage IIS server for this. Is there a way to actually run the server (first start of tests) and making the server use a special "test" DB (for example an in-memory RavenDB) emptied after each scenario (and filled during the background).

Is there a better or simpler way to do this?

CharlesB
  • 86,532
  • 28
  • 194
  • 218
Blackmore
  • 41
  • 1

2 Answers2

0

I'm fairly new to this too, so take the answers with a pinch of salt, but as noone else has answered...

Is there a way to actually run the server (first start of tests) ...

You could use IIS Express, which can be called via the command line. You can spin up your website before any tests run (which I believe you can do with the [BeforeTestRun] attribute in SpecFlow) with a call via System.Diagnostics.Process.

The actual command line would be something like e.g.

iisexpress.exe /path:c:\iisexpress\<your-site-published-to-filepath> /port:<anyport> /clr:v2.0

... and making the server use a special "test" DB (for example an in-memory RavenDB) emptied after each scenario (and filled during the background).

In order to use a special test DB, I guess it depends how your data access is working. If you can swap in an in-memory DB fairly easily then I guess you could do that. Although my understanding is that integration tests should be as close to production env as possible, so if possible use the same DBMS you're using in production.

What I'm doing is just doing a data restore to my test DB from a known backup of the prod DB, each time before the tests run. I can again call this via command-line/Process before my tests run. For my DB it's a fairly small dataset, and I can restore just the tables relevant to my tests, so this overhead isn't too prohibitive for integration tests. (It wouldn't be acceptable for unit tests however, which is where you would probably have mock repositories or in-memory data.)

ngm
  • 7,277
  • 1
  • 53
  • 62
0

Since you're already using SpecFlow take a look at SpecRun (http://www.specrun.com/).

It's a test runner which is designed for SpecFlow tests and adds all sorts of capabilities, from small conveniences like better formatting of the Test names in the Test Explorer to support for running the same SpecFlow test against multiple targets and config file transformations.

With SpecRun you define a "Profile" which will be used to run your tests, not dissimilar to the VS .runsettings file. In there you can specify:

<DeploymentTransformation>
  <Steps>
      <IISExpress webAppFolder="..\..\MyProject.Web" port="5555"/>
  </Steps>
</DeploymentTransformation>

SpecRun will then start up an IISExpress instance running that Website before running your tests. In the same place you can also set up custom Deployment Transformations (using the standard App.Config transformations) to override the connection strings in your app's Web.config so that it points to the in-memory DB.

The only problem I've had with SpecRun is that the documentation isn't great, there are lots of video demonstrations but I'd much rather have a few written tutorials. I guess that's what StackOverflow is here for.

James McCalden
  • 3,696
  • 2
  • 16
  • 18