Master technical and career interviews with structured answers—short definition, real examples, pitfalls, and how to answer in 60–90 seconds.
Short answer: xUnit encourages constructor injection for setup instead of [SetUp] methods. It uses [Fact] and [Theory] attributes for test methods, while NUnit/MSTest use [Test] and [TestMethod]. xUnit does not use [Test…
Short answer: [Fact]: Defines a parameterless test method representing a single test case. [Theory]: Defines a parameterized test that runs multiple times with different data inputs, provided by [InlineData] or other dat…
Short answer: Using [Theory] and data attributes like [InlineData]: [Theory] [InlineData(2, 3, 5)] [InlineData(10, 20, 30)] public void Add_ReturnsSum(int a, int b, int expected) { var calculator = new Calculator(); var…
Short answer: Use the constructor for setup code. Implement IDisposable interface for teardown (cleanup) code. Example: public class DatabaseTests : IDisposable Example code { public DatabaseTests() { // Setup } [Fact] p…
Short answer: Use the Skip property on [Fact] or [Theory]: [Fact(Skip = "Reason for skipping")] public void SkippedTest() { } Real-world example (ShopNest) ShopNest unit tests cover pricing and discount rules s…
Short answer: Group related tests in the same class. Use Collection attribute to group classes that share setup/teardown or should not run in parallel. [Collection("Database collection")] public class TestClass…
Short answer: Test fixtures provide a way to share setup and cleanup code between tests. xUnit supports: Class Fixtures: Shared across all tests in a class. Collection Fixtures: Shared across multiple test classes. They…
Short answer: Use the dotnet test CLI command: dotnet test YourTestProject.csproj This runs all tests in the project and outputs results in the console. Additional options allow filtering and outputting reports. NUnit Fr…
Short answer: NUnit uses [Test] for test methods, whereas xUnit uses [Fact]. NUnit uses [SetUp] and [TearDown] for setup and cleanup, while xUnit uses constructors and IDisposable. NUnit supports [TestCase] for parameter…
Short answer: [TestCase(2, 3, 5)] [TestCase(10, 20, 30)] public void Add_ReturnsSum(int a, int b, int expected) Example code { var calculator = new Calculator(); var result = calculator.Add(a, b); Assert.AreEqual(expecte…
Short answer: [Test] public void Divide_ByZero_ThrowsException() Example code { var calculator = new Calculator(); Assert.Throws<DivideByZeroException>(() => calculator.Divide(10, 0)); } Real-world example (Shop…
Short answer: Use the [Category("CategoryName")] attribute to group tests, allowing filtering by category during test runs. [Test, Category("Integration")] public void IntegrationTest() { } Real-world…
Short answer: Use [Ignore("Reason")] to skip tests unconditionally, or [Category] combined with test runner filters. For conditional ignoring, you can use Assume statements or custom logic inside tests. Real-wo…
Short answer: Download and use nunit3-console.exe from NUnit site: nunit3-console.exe YourTestAssembly.dll It runs all tests in the assembly and outputs results. Real-world example (ShopNest) ShopNest unit tests cover pr…
Short answer: Yes, NUnit integrates seamlessly with CI/CD tools like Azure DevOps, Jenkins, GitHub Actions, and others using command-line runners or plugins, allowing automated test execution during builds and deployment…
Short answer: [TestClass] public class CalculatorTests { [TestMethod] public void Add_ReturnsSum() Example code { var calculator = new Calculator(); var result = calculator.Add(2, 3); Assert.AreEqual(5, result); } } Real…
Short answer: MSTest is Microsoft's official framework; NUnit and xUnit are community-driven. MSTest uses [TestClass] and [TestMethod] attributes; xUnit uses [Fact], NUnit uses [Test]. MSTest has less flexibility in data…
Short answer: ttributes? [TestInitialize] runs code before each test method to set up prerequisites. [TestCleanup] runs after each test method to clean up resources. [TestInitialize] public void Setup() { /* setup code *…
Short answer: [TestInitialize] runs code before each test method to set up prerequisites. [TestCleanup] runs after each test method to clean up resources. [TestInitialize] public void Setup() { /* setup code */ } [TestCl…
Short answer: [TestMethod] [ExpectedException(typeof(DivideByZeroException))] public void Divide_ByZero_ThrowsException() Example code { var calculator = new Calculator(); calculator.Divide(10, 0); } Real-world example (…
Short answer: How? Yes, MSTest supports data-driven tests using [DataTestMethod] and [DataRow] attributes: [DataTestMethod] [DataRow(2, 3, 5)] [DataRow(10, 20, 30)] public void Add_ReturnsSum(int a, int b, int expected)…
Short answer: Yes, MSTest supports data-driven tests using [DataTestMethod] and [DataRow] ttributes: [DataTestMethod] [DataRow(2, 3, 5)] [DataRow(10, 20, 30)] public void Add_ReturnsSum(int a, int b, int expected) { var…
Short answer: Use the [TestCategory("CategoryName")] attribute to group tests for filtering. [TestMethod] [TestCategory("Integration")] public void IntegrationTest() { } Real-world example (ShopNest)…
Short answer: Use the [Ignore("Reason")] attribute on the test method or class. [Ignore("Test is temporarily disabled")] [TestMethod] public void SkippedTest() { } Real-world example (ShopNest) ShopNe…
Short answer: Use dotnet test CLI for .NET Core MSTest projects: dotnet test YourTestProject.csproj In Azure DevOps, use the Visual Studio Test task or the DotNetCoreCLI task to run tests during builds and releases. Real…
Unit Testing C# Programming Tutorial · Testing
Short answer: xUnit encourages constructor injection for setup instead of [SetUp] methods. It uses [Fact] and [Theory] attributes for test methods, while NUnit/MSTest use [Test] and [TestMethod]. xUnit does not use [TestInitialize]/[TestCleanup] but favors class fixtures and constructor/dispose patterns. xUnit is better integrated with .NET Core and supports parallel test execution by default.
ShopNest unit tests cover pricing and discount rules so a bad coupon change fails in CI before customers see it.
Unit Testing C# Programming Tutorial · Testing
Short answer: [Fact]: Defines a parameterless test method representing a single test case. [Theory]: Defines a parameterized test that runs multiple times with different data inputs, provided by [InlineData] or other data sources.
Arrange a cart with 2 items → Act Checkout() → Assert total and that payment was called once.
Unit Testing C# Programming Tutorial · Testing
Short answer: Using [Theory] and data attributes like [InlineData]: [Theory] [InlineData(2, 3, 5)] [InlineData(10, 20, 30)] public void Add_ReturnsSum(int a, int b, int expected) { var calculator = new Calculator(); var result = calculator.Add(a, b); Assert.Equal(expected, result); }
Using [Theory] and data attributes like [InlineData]: [Theory] [InlineData(2, 3, 5)] [InlineData(10, 20, 30)] public void Add_ReturnsSum(int a, int b, int expected)
{
var calculator = new Calculator();
var result = calculator.Add(a, b); Assert.Equal(expected, result); }
ShopNest unit tests cover pricing and discount rules so a bad coupon change fails in CI before customers see it.
Unit Testing C# Programming Tutorial · Testing
Short answer: Use the constructor for setup code. Implement IDisposable interface for teardown (cleanup) code. Example: public class DatabaseTests : IDisposable
{
public DatabaseTests()
{ // Setup } [Fact] public void TestMethod() { }
public void Dispose()
{ // Cleanup }
}
For shared context across multiple tests, use class fixtures or collection fixtures.
ShopNest unit tests cover pricing and discount rules so a bad coupon change fails in CI before customers see it.
Unit Testing C# Programming Tutorial · Testing
Short answer: Use the Skip property on [Fact] or [Theory]: [Fact(Skip = "Reason for skipping")] public void SkippedTest() { }
ShopNest unit tests cover pricing and discount rules so a bad coupon change fails in CI before customers see it.
Unit Testing C# Programming Tutorial · Testing
Short answer: Group related tests in the same class. Use Collection attribute to group classes that share setup/teardown or should not run in parallel. [Collection("Database collection")] public class TestClass1 { } [Collection("Database collection")] public class TestClass2 { }
ShopNest unit tests cover pricing and discount rules so a bad coupon change fails in CI before customers see it.
Unit Testing C# Programming Tutorial · Testing
Short answer: Test fixtures provide a way to share setup and cleanup code between tests. xUnit supports: Class Fixtures: Shared across all tests in a class. Collection Fixtures: Shared across multiple test classes. They are implemented by creating a fixture class and injecting it into test classes via constructor.
ShopNest unit tests cover pricing and discount rules so a bad coupon change fails in CI before customers see it.
Unit Testing C# Programming Tutorial · Testing
Short answer: Use the dotnet test CLI command: dotnet test YourTestProject.csproj This runs all tests in the project and outputs results in the console. Additional options allow filtering and outputting reports. NUnit Framework
ShopNest unit tests cover pricing and discount rules so a bad coupon change fails in CI before customers see it.
Unit Testing C# Programming Tutorial · Testing
Short answer: NUnit uses [Test] for test methods, whereas xUnit uses [Fact]. NUnit uses [SetUp] and [TearDown] for setup and cleanup, while xUnit uses constructors and IDisposable. NUnit supports [TestCase] for parameterized tests, xUnit uses [Theory] with [InlineData]. NUnit has more built-in attributes like [Category] for grouping tests.
ShopNest unit tests cover pricing and discount rules so a bad coupon change fails in CI before customers see it.
Unit Testing C# Programming Tutorial · Testing
Short answer: [TestCase(2, 3, 5)] [TestCase(10, 20, 30)] public void Add_ReturnsSum(int a, int b, int expected)
{
var calculator = new Calculator();
var result = calculator.Add(a, b); Assert.AreEqual(expected, result); }
ShopNest unit tests cover pricing and discount rules so a bad coupon change fails in CI before customers see it.
Unit Testing C# Programming Tutorial · Testing
Short answer: [Test] public void Divide_ByZero_ThrowsException()
{
var calculator = new Calculator(); Assert.Throws<DivideByZeroException>(() => calculator.Divide(10, 0)); }
Arrange a cart with 2 items → Act Checkout() → Assert total and that payment was called once.
Unit Testing C# Programming Tutorial · Testing
Short answer: Use the [Category("CategoryName")] attribute to group tests, allowing filtering by category during test runs. [Test, Category("Integration")] public void IntegrationTest() { }
ShopNest unit tests cover pricing and discount rules so a bad coupon change fails in CI before customers see it.
Unit Testing C# Programming Tutorial · Testing
Short answer: Use [Ignore("Reason")] to skip tests unconditionally, or [Category] combined with test runner filters. For conditional ignoring, you can use Assume statements or custom logic inside tests.
ShopNest unit tests cover pricing and discount rules so a bad coupon change fails in CI before customers see it.
Unit Testing C# Programming Tutorial · Testing
Short answer: Download and use nunit3-console.exe from NUnit site: nunit3-console.exe YourTestAssembly.dll It runs all tests in the assembly and outputs results.
ShopNest unit tests cover pricing and discount rules so a bad coupon change fails in CI before customers see it.
Unit Testing C# Programming Tutorial · Testing
Short answer: Yes, NUnit integrates seamlessly with CI/CD tools like Azure DevOps, Jenkins, GitHub Actions, and others using command-line runners or plugins, allowing automated test execution during builds and deployments. MSTest Framework
ShopNest unit tests cover pricing and discount rules so a bad coupon change fails in CI before customers see it.
Unit Testing C# Programming Tutorial · Testing
Short answer: [TestClass] public class CalculatorTests { [TestMethod] public void Add_ReturnsSum()
{
var calculator = new Calculator();
var result = calculator.Add(2, 3); Assert.AreEqual(5, result); }
}
ShopNest unit tests cover pricing and discount rules so a bad coupon change fails in CI before customers see it.
Unit Testing C# Programming Tutorial · Testing
Short answer: MSTest is Microsoft's official framework; NUnit and xUnit are community-driven. MSTest uses [TestClass] and [TestMethod] attributes; xUnit uses [Fact], NUnit uses [Test]. MSTest has less flexibility in data-driven tests compared to NUnit’s [TestCase] and xUnit’s [Theory]. xUnit promotes constructor-based setup, MSTest uses [TestInitialize].
ShopNest unit tests cover pricing and discount rules so a bad coupon change fails in CI before customers see it.
Unit Testing C# Programming Tutorial · Testing
Short answer: ttributes? [TestInitialize] runs code before each test method to set up prerequisites. [TestCleanup] runs after each test method to clean up resources. [TestInitialize] public void Setup() { /* setup code */ } [TestCleanup] public void Cleanup() { /* cleanup code */ }
ShopNest unit tests cover pricing and discount rules so a bad coupon change fails in CI before customers see it.
Unit Testing C# Programming Tutorial · Testing
Short answer: [TestInitialize] runs code before each test method to set up prerequisites. [TestCleanup] runs after each test method to clean up resources. [TestInitialize] public void Setup() { /* setup code */ } [TestCleanup] public void Cleanup() { /* cleanup code */ }
ShopNest unit tests cover pricing and discount rules so a bad coupon change fails in CI before customers see it.
Unit Testing C# Programming Tutorial · Testing
Short answer: [TestMethod] [ExpectedException(typeof(DivideByZeroException))] public void Divide_ByZero_ThrowsException()
{
var calculator = new Calculator(); calculator.Divide(10, 0); }
Arrange a cart with 2 items → Act Checkout() → Assert total and that payment was called once.
Unit Testing C# Programming Tutorial · Testing
Short answer: How? Yes, MSTest supports data-driven tests using [DataTestMethod] and [DataRow] attributes: [DataTestMethod] [DataRow(2, 3, 5)] [DataRow(10, 20, 30)] public void Add_ReturnsSum(int a, int b, int expected)
{
var calculator = new Calculator();
var result = calculator.Add(a, b); Assert.AreEqual(expected, result); }
ShopNest unit tests cover pricing and discount rules so a bad coupon change fails in CI before customers see it.
Unit Testing C# Programming Tutorial · Testing
Short answer: Yes, MSTest supports data-driven tests using [DataTestMethod] and [DataRow] ttributes: [DataTestMethod] [DataRow(2, 3, 5)] [DataRow(10, 20, 30)] public void Add_ReturnsSum(int a, int b, int expected) { var calculator = new Calculator(); var result = calculator.Add(a, b); ssert.AreEqual(expected, result); } Yes, MSTest supports data-driven tests using… [DataTestMethod] and [DataRow] ttributes: [DataTestMethod]…
[DataRow(2, 3, 5)] [DataRow(10, 20, 30)] public void Add_ReturnsSum(int a, int b, int expected) { var calculator = new Calculator(); var result = calculator.Add(a, b); ssert.AreEqual(expected, result); }
ShopNest unit tests cover pricing and discount rules so a bad coupon change fails in CI before customers see it.
Unit Testing C# Programming Tutorial · Testing
Short answer: Use the [TestCategory("CategoryName")] attribute to group tests for filtering. [TestMethod] [TestCategory("Integration")] public void IntegrationTest() { }
ShopNest unit tests cover pricing and discount rules so a bad coupon change fails in CI before customers see it.
Unit Testing C# Programming Tutorial · Testing
Short answer: Use the [Ignore("Reason")] attribute on the test method or class. [Ignore("Test is temporarily disabled")] [TestMethod] public void SkippedTest() { }
ShopNest unit tests cover pricing and discount rules so a bad coupon change fails in CI before customers see it.
Unit Testing C# Programming Tutorial · Testing
Short answer: Use dotnet test CLI for .NET Core MSTest projects: dotnet test YourTestProject.csproj In Azure DevOps, use the Visual Studio Test task or the DotNetCoreCLI task to run tests during builds and releases.
ShopNest unit tests cover pricing and discount rules so a bad coupon change fails in CI before customers see it.
Install Toolliyo like an app Free
Home-screen access to tutorials, coding practice & career tools — no app store needed.
On iPhone/iPad: tap Share then Add to Home Screen.