.Net Framework 4.6.1 MVC integration testing

516 views Asked by At

I am having a hard time trying to find sources of how can I run Integration Tests on my old Net Framework 4.6.1 MVC application. I tried a lot of guides I found, but none of them works for one reason or another.

My application is way to big to upgrade it to Net 6, which would make this testing much easier. I tried running OWIN TestServer, but it always results in 404 errors.

So I would like to know, how to approach integration testing on a old mvc? Am I following the right path searching for a solution with OWIN TestServer? Anything else I could try? Thought of Selenium too, but couldnt get it to start a fake server just to run the tests automatically, I needs a command to initialize my app on IIS, and we need the tests to run automatically through azure CI pipeline.

My app is very old so I tried removing Global.asax and using only the owin pipeline through Startup.cs, but it showed an error message "No HTTP resource was found that matches the request uri", tried many fixes for Route configuration and such, no success. Tried running OWIN TestServer with both global.asax and startup.cs on the solution but did not work, tried Selenium too but it does not start a fake server automatically, preferably in memory just like the most recent versions of TestServer for net core+.

Tried also following this: https://www.strathweb.com/2013/12/owin-memory-integration-testing/

1

There are 1 answers

1
MD Zand On

There are lots of huge, working, legacy products based on .Net framework. They have been designed years (lets say 8-10) ago. So that time testing stack was not as it is nowadays. In addition to unit testing (which is completely supported in .Net framework) you can also have integration and end to end test, although not as straightforward as it is in .Net (core). These are my experience in the case of designing effective test sets for a huge .Net framework product:

  1. Unit test could be done perfectly
  2. If you have a service layer before you api/mvc controllers you can have a set of automated integration tests (With no mocking). You need to use some sort of database restore (We use sql snapshots because of its speed). This set of service layer test play an important role in our QA.
  3. You need to set up CI/CD tools like Azure DevOps or Jenkins (We use the latter) to have real end to end tests. For each release you need at least 1 deployed instance (We have dozens because of several common effective configurations our product may have) of your system to be exposed to automated Selenium tests.

Although testing at controllers are possible (see here) we found it to heavy to develop and maintain for our product. But for yours it may be suitable.

More over I recommend having a migration project. First of all try to keep you code updated to the latest .Net framework version (Which is not so hard). If rewriting the code with a parallel team is not an option (Although it needs huge resources but it is still less painful one!), you may consider a step by step module/domain changes and moving not technology intensive codes to .Net standard libraries (which could be used both in .net framework and .Net) and also think about extracting modules/domains to .Net micro services one by one.