简体   繁体   中英

How to write integration tests?

My team develops a Web API 2 application using Entity framework 6 ORM.

Our application acts as an email, and it's main purpose and action is to send a letter from one client to another.

Since it's the application's main purpose, we'd all like to have an integration test that will assure us that a letter is sent correctly. That is because we don't want to accidentally insert code that will break that.

When sending a letter the main actions that happen and that we'd like to test are-

  • A letter is received through HTTP Post method and is validated on server
  • The letter is saved to the Database .
  • The letter is serialized.
  • The serialized letter is sent to the specified destinations through an external module.
  • The letter is deserialized on reciever side.
  • The letter is added to recieved client's database.

I'm asking this because I'm clueless about how to approach this, yet I really want that sort of test which I can rely on.

How should a test for this be set? Where do I start? How to achieve an actual letter sending through a test and make sure it works?

It doesn't have to be an end to end test.

Thanks

Edit:

I don't mind tests to take long time, they can be run at night, but I want them to verify as much as possible that the application main parts are working as expected.

I would set up multiple, non-actual code tests to verify your logic:

  1. Reception of the letter, and it's logic
  2. Verify that the save method to the database is invoked only when it should
  3. Verify the serialization/deserialization bits of code
  4. Verify that the destination picker module is working correctly.

Once you have these "non-invoking" tests, you know that all the bits of your system are working correctly individually. You can then set up a unit-test with some kind of marking (ie TestCategory("SUPERSLOW")) and then have that run manually against a mocked set of recipients for verification during integration test runs, NOT as part of your CI.

Keywords here are:

  • SOLID principles
  • Separation of Concerns
  • Mocking
  • Continuous Integration
  • Inversion of Control

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM