.NET

Unit Testing & xUnit

xUnit framework, test cases, assertions, Moq, FluentAssertions, code coverage, TDD principles

20 câu hỏi phỏng vấn·
Mid-Level
1

What is xUnit in the context of .NET?

Câu trả lời

xUnit is an open-source unit testing framework for .NET, inspired by JUnit and NUnit. It uses attributes like [Fact] for simple tests and [Theory] for parameterized tests. xUnit encourages best practices like test isolation (each test creates a new test class instance) and avoids shared state via traditional Setup/Teardown methods.

2

What is the difference between [Fact] and [Theory] in xUnit?

Câu trả lời

[Fact] decorates a simple test that runs once without parameters, while [Theory] decorates a parameterized test that runs multiple times with different values provided via [InlineData], [MemberData], or [ClassData]. Using [Theory] avoids code duplication when testing multiple similar scenarios with different data.

3

How to use [InlineData] with [Theory] in xUnit?

Câu trả lời

[InlineData] provides data directly in the attribute for a [Theory] test, allowing the same test to run with different values. Each [InlineData] attribute represents a distinct test case. This approach is ideal for testing multiple simple scenarios without creating separate data classes, reducing boilerplate code.

4

What is the main advantage of Moq in .NET unit testing?

5

How to configure a mock with Moq so that a method returns a specific value?

+17 câu hỏi phỏng vấn

Nắm vững .NET cho lần phỏng vấn tiếp theo

Truy cập tất cả câu hỏi, flashcards, bài kiểm tra kỹ thuật, bài tập code review và mô phỏng phỏng vấn.

Bắt đầu miễn phí