Welcome! 👋
This project is a revisited and improved version of my first NUnit API tests tutorial. Here, we automate API tests in C# using NUnit, RestSharp, and Allure Reports. The goal is to create robust, reusable, and maintainable tests that can run locally or in CI/CD pipelines.
You can read the full article here: Dev.to Tutorial 📖
- ✅ Automated API tests using NUnit and C#
- ✅ REST API requests handled via RestSharp
- ✅ Configurable environment variables via
.runsettings - ✅ Sensitive data protection for API keys & user data
- ✅ Allure report integration for test results
- ✅ Clean, reusable, and maintainable code structure
- ✅ Example API: DummyJSON
| Endpoint | Test | Expected Result |
|---|---|---|
/users |
Get all users | Returns 200 OK and a list of users |
/users/add |
Create a new user | Returns 201 Created with user data |
Also includes an example for NASA API testing using .runsettings for secure API keys.
git clone https://github.com/m4rri4nne/ApiTestsWithNUnit.git
cd ApiTestsWithNUnitdotnet restore- Create a .runsettings file (already included as an example)
- Add your API keys and variables
- Do NOT commit sensitive info
⚠️
Example .runsettings:
<RunSettings>
<TestRunParameters>
<Parameter name="BaseUrl" value="https://dummyjson.com" />
<Parameter name="UserName" value="John" />
<Parameter name="LastName" value="Doe" />
<Parameter name="Email" value="john.do@example.com" />
<Parameter name="ApiToken" value="YOUR_API_KEY" />
</TestRunParameters>
</RunSettings>dotnet test --settings .runsettingsTests will execute and results will be displayed in the console.
After running the tests:
allure serve ./bin/Debug/net8.0/allure-resultsThis will open a beautiful interactive report in your browser. 🎉
- Use Setup() in tests to avoid duplication
- Abstract API requests to make tests maintainable
- Keep sensitive data out of version control
- Allure reports give a quick visual overview of test results
- Tests are reusable and can be extended for other endpoints
Marianne – Sharing my journey in C#, NUnit, and API testing 💻
✨ Enjoy coding and happy testing! ✨
