.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, 기술 테스트, 코드 리뷰 연습, 면접 시뮬레이터에 접근하세요.

무료로 시작하기