Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Integration tests detailed

I have a WCF service that accesses the database and adds data to it. now, I want to do some integration and/or system tests (automated).

How do I do it ?

I have to access the database, load initial data, call the service and then verify whether the data expected was actually loaded in the table.

is there any strategy for doing that you would recommend ?

I'm using WCF, Entity Framework, SQL Server, MSTests.

like image 360
Attilah Avatar asked Apr 22 '26 03:04

Attilah


1 Answers

If you don't mind your test project taking a dependency on Entity Framework then here's how I would approach this.

  1. In the test project, create an EF model from the database, using only the table(s) you expect to be testing.
  2. Add a service reference to the WCF service from the test project.
  3. Create a test in the test project. In this test, use the EF context to create your initial test data.
  4. Call your service from the test.
  5. Check the database for the appropriate data, call your Assert(s).
  6. Clean up the database.

You should also consider using a lightweight file-based/in-memory database such as SQLite for this task. One simple way of achieving this would be to use EF to generate a model from your DB, then use the Update Database From Model tool to generate the SQL that will create the appropriate tables and constraints in your SQLite instance. This means no risk of munting the data in your main/dev DB and potentially faster tests.

Also regarding steps 3 and 6, some people would advocate using the setup/clean-up/tear-down affordance built in to MSTest. I generally don't start using these until I can see them helping with reducing code duplication, because in my opinion they make tests less clear and readable, but that's a personal thing.

like image 74
Martin Doms Avatar answered Apr 23 '26 17:04

Martin Doms



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!