Did you ever try automate your APIs tests and don't know how to start it? This tutorial will help you to automate your API Test using NUNit and C# ...
For further actions, you may consider blocking this person and/or reporting abuse
Awesome content! I don't know anything about c# but your didactics really helped create a pleasure experience
One quick tip if you allow me:
You can insert the language after the codeblock symbol to enable syntax highlighting like so:
Thanks for the tip, i've updated using it <3
Although your approach to testing API was great, I wouldn't use RestSharp and would rather write my own HTTP client. However, your approach was completely robust.
Thanks for your great post.
Thanks! I’ll try do without restsharp next time ❤️
Great content! I like it. It's beneficial and easy to understand.
I apologize for being intrusive, but I couldn't help but notice that the FakeRestAPI's response StatusCode are not following the best Rest API practices. The Post method should return 201 (Created), the Delete and Update/PUT methods should return 204 (NoContent)
I appreciate the informative article you've written. Thank you🙂.
Thanks for the information. I didn’t create the API, I just used and create the tests based on swagger documentation. For sure, they not use the best practices for status code 🥲
Amazing content, I going to use this as reference for when I implementing tests in my projects
C# it's my first stack, great content!
Great post!
Great article!
sweeeeet
Nicee
So good content!
Great post, thanks for this!
Just a point though - since your tests are calling a physical web address and checking the response, wouldn't these be integration tests instead of unit tests?
If the website is down, the tests will fail - which wouldn't be a result of anything in the code, but an external system.
I said in the article that is an integration test, NUnit is just the name of the framework.
Ah, you did indeed. 😳
I'm skeptical of unit tests that just test for nulls or empty.
Such things can be checked with asserts in the code.
What unit tests should be checking for is that if you write X to the API you get back X. If you ask it to calculate something with the data you gave, it should return the proper calculation.
In other words unit tests should exercise the logic of the API (which you can measure with code coverage tools) and not merely do asserts.
Asserts are better done in the code itself.
I worry many people just write useless unit tests that don't really TEST the application, they just ASSERT certain things about data.
The purpose of the article is to help those who want to start test APIs using the stack, not to decide or make an analysis about if the tests will be delivering value. As a said in the article, the tests made were integration tests, in a real scenario, probably you’ll have more tests than those, like performance and data consistency, but this is just an example.
Fair enough
Too many simple tests just adds a lot of load to the program while providing little value. Tests need to be sneaky and really push the code to reveal it's bugs.