Junior — Middle
Do you have experience creating and executing integration tests for software systems?
sobes.tech AI
Answer from AI
Yes, I have experience creating and executing integration tests in C#. Usually, I use frameworks such as NUnit or xUnit, along with mocking libraries (e.g., Moq) and tools for setting up the test environment (e.g., Docker or built-in test servers).
Integration tests verify the interaction of multiple system components, such as the controller working with the database and services. An example of a simple integration test using xUnit and Entity Framework Core InMemory:
public class UserServiceIntegrationTests
{
private readonly UserService _userService;
private readonly DbContextOptions<AppDbContext> _options;
public UserServiceIntegrationTests()
{
_options = new DbContextOptionsBuilder<AppDbContext>()
.UseInMemoryDatabase(databaseName: "TestDb")
.Options;
var context = new AppDbContext(_options);
_userService = new UserService(context);
}
[Fact]
public void AddUser_ShouldAddUserToDatabase()
{
var user = new User { Id = 1, Name = "Test User" };
_userService.AddUser(user);
using var context = new AppDbContext(_options);
var addedUser = context.Users.Find(1);
Assert.NotNull(addedUser);
Assert.Equal("Test User", addedUser.Name);
}
}
This test checks that the service interacts correctly with the database, which goes beyond unit testing and is close to real application operation.