Vik K
Vik K

Reputation: 33

Unit testing Rest end points

I've REST end points written in java. And there's c# code in the app that invokes these end points using RestClient. I'm thinking of writing unit tests for these. Just wondering what would be the best approach for this? Moq framework or NUNIT or something else? Any ideas?

Thanks.

Upvotes: 0

Views: 427

Answers (2)

Code-Apprentice
Code-Apprentice

Reputation: 83517

Unit test are typically written in the same language as the code being tested. In fact, if you are testing with a different language, I would argue that you are no longer writing unit tests. Since your REST API is written in Java, I suggest checking out JUnit to test it. This is a popular testing framework in Java.

Upvotes: 0

Liam Rougoor
Liam Rougoor

Reputation: 31

If you want to test the REST end points in Java, you could use a mock framework like Mockito (https://site.mockito.org/) to mock any data you need. Usually when you test REST end points, you should test whether the method returns the correct status code and data. That data should be mocked.

If you want to test whether your C# app retrieves the correct data from your Java end points, that's usually considered an integration test, rather than a unit test, since the test relies on the correctness of your Java code. This is still something you could test, but note that if the test fails, this could be due to errors in the Java code and not necessarily the C# method call.

If you want to truly unit test your C# code, you should mock the result of the method calls to the REST end points. I know that it's possible in Java with Mockito, but I'm not sure what frameworks are out there that support it for C#.

Upvotes: 1

Related Questions