How to enter database data for testing integration in C #?

I recently wrote some integration tests with ASP.Net MVC controller actions and was disappointed with the complexity of setting up test data that must be present to run the test.

For example, I want to test the actions of "add", "edit" and "delete" the controller. I can write an β€œadd” test, but then find that to record the β€œedit” test, I either had to call the β€œadd” test code to create a record so that I could edit it, or make a lot of settings in the test class, none of which is not particularly attractive.

Ideally, I want to use or develop an integration test environment to make it easier to add seed to the reusable path for integration tests so that the arr / act / assert test organization aspect can focus on organizing what I especially need to organize my test, rather than touching yourself, with the placement of a load of reference data indirectly related to the code under the test.

I use NHibernate, but I believe that any functions for sowing data should not forget about it and be able to directly manipulate the database; ORM may change, but I will always use the SQL database.

I use NUnit, so I plan to connect to the installation / debugging of test / testfixture (but I think that a good solution could potentially be passed to other test environments).

I use FluentMigrator in my main project to control the scheme and sow the reference data, so it would be nice, but not important, to be able to use the FluentMigrator infrastructure for a consistent approach to the solution.

So my question is: "How do you use database data to test integration in C #?" Do you execute SQL directly? Do you use a framework?

+4
source share
2 answers

I do not know if this needs to be done β€œcorrectly”, but I have always sowed using my add / create methods.

+1
source

You can perform integration testing on Sql Server Compact, you will have a .sdf file, and you can connect to it by specifying the file path as the connection string. It would be faster and easier to set up and work.

Integration testing will probably not require millions of rows of data. You can paste your test data into your database and save it as TestDbOriginal.sdf .

When you run your tests, just make a copy of this " TestDbOriginal.sdf " and work on this copy that is already seeded with data. If you want to test a specific scenario, you will need to prepare your data by calling some methods, such as adding, deleting, editing.

When you start production or performance testing, return to the original version of the server, whether it be Sql Server 2008 or something else.

+1
source

All Articles