I am trying to write integration tests in C# for my C# asp.NET Framework 4.6.1 WebAPI which contains simple CRUD functionalities.
I have found little to no documentation on making automated integration tests for .NET Framework 4.6.1 using Microsoft.AspNet.WebApi 5.2.4. I've only found relatively old articles and video's on making integration tests for .NET Core using Xunit and Nunit, but ran into a lot of compatibility issues while trying to somehow make them work on .NET Framework 4.6.1 and WebApi 5.2.4.
I know this question could be considered primarily opinion based, but I would really appreciate any help on the matter.
How to write automated tests for an .NET Framework 4.6.1 Microsoft.AspNet.WebApi 5.2.4 application?
- Which packages could I use?
- How do I configure these packages properly?
- How should I use these packages?
I currently do not use Owin for hosting my application, but invoke my configurations in Global.asax, but I could create a solution configuration which builds the project using Owin if needed.
-
1I don't believe you "ran into a lot of compatibility issues". Those are well supported on .NET Framework. Show more info please.Lex Li– Lex Li2018年07月24日 19:03:51 +00:00Commented Jul 24, 2018 at 19:03
-
1@LexLi Could you help me out by telling me which packages you used which are well supported? I'm relatively new to c# asp.net and I'm really stuck here.Joas– Joas2018年07月24日 19:05:25 +00:00Commented Jul 24, 2018 at 19:05
-
Both Xunit and NUnit are well supported on .NET Framework.Lex Li– Lex Li2018年07月24日 19:06:16 +00:00Commented Jul 24, 2018 at 19:06
-
1@LexLi For writing unit tests, yes: I've had no problems so far. But I need to write integration tests. I've read a lot about those today and I'm pretty sure I need some way to host the application (in-memory) and a way to communicate to it like a normal http-client would.Joas– Joas2018年07月24日 19:08:41 +00:00Commented Jul 24, 2018 at 19:08
-
1I am confused by you. It is just a simple Web API, so why cannot you host it on IIS (assuming its production environment would also be on IIS) and then write a few test cases in NUnit or Xunit to get the job done. Yes, you might use OWIN to self host it and test, but why should you?Lex Li– Lex Li2018年07月24日 19:11:35 +00:00Commented Jul 24, 2018 at 19:11
1 Answer 1
After reading the comments it sounds like you’re looking for owin TestServer.
https://www.strathweb.com/2012/06/asp-net-web-api-integration-testing-with-in-memory-hosting/