.NET

Unit Testing & xUnit

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

20 面接問題·
Mid-Level
1

What is xUnit in the context of .NET?

回答

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?

回答

[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?

回答

[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 面接問題

次の面接に向けて.NETをマスター

すべての問題、flashcards、技術テスト、コードレビュー演習、面接シミュレーターにアクセス。

無料で始める