13

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.

asked Jul 24, 2018 at 18:53
8
  • 1
    I don't believe you "ran into a lot of compatibility issues". Those are well supported on .NET Framework. Show more info please. Commented 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. Commented Jul 24, 2018 at 19:05
  • Both Xunit and NUnit are well supported on .NET Framework. Commented 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. Commented Jul 24, 2018 at 19:08
  • 1
    I 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? Commented Jul 24, 2018 at 19:11

1 Answer 1

4

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/

answered Jul 24, 2018 at 19:34
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you for your response. I've read the article earlier today, but since it was from 2012 I doubted it's reliability (as we all know, a lot can change in 6 years). It also doesn't mention anything about the owin TestServer. I've also worked with the owin TestServer earlier today, but it doesn't seem to support .NET Framework 4.6.1 Microsoft.AspNet.WebApi 5.2.4 applications, since it references interfaces only found in Microsoft.AspNetCore (For example: an IApplicationBuilder is passed to the Startup.Configure method, which takes an IAppBuilder in Microsoft.AspNet instead)
Look at the older version of the owin test server, they should have the correct interfaces.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.