Master technical and career interviews with structured answers—short definition, real examples, pitfalls, and how to answer in 60–90 seconds.
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 sour…
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 = calcu…
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() { }…
Answer: Use the Skip property on [Fact] or [Theory]: [Fact(Skip = "Reason for skipping")] public void SkippedTest() { } What interviewers expect A clear definition tied to Testing in Unit Testing projects Trade-offs (per…
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("Datab…
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 implemente…
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 Framewor…
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, xU…
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); ssert.AreEqual(expected, result); } What i…
Answer: [Test] public void Divide_ByZero_ThrowsException() { var calculator = new Calculator(); ssert.Throws<DivideByZeroException>(() => calculator.Divide(10, 0)); } What interviewers expect A clear…
Answer: Use the [Category("CategoryName")] attribute to group tests, allowing filtering by category during test runs. [Test, Category("Integration")] public void IntegrationTest() { } What interviewers expect A clear def…
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. What interviewers expec…
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. What interviewers expect A clear definition tied to Testing in U…
Answer: Yes, NUnit integrates seamlessly with CI/CD tools like Azure DevOps, Jenkins, GitHub ctions, and others using command-line runners or plugins, allowing automated test execution during builds and deployments. MSTe…
Answer: [TestClass] public class CalculatorTests { [TestMethod] public void Add_ReturnsSum() { var calculator = new Calculator(); var result = calculator.Add(2, 3); ssert.AreEqual(5, result); } } What interviewers expect…
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…
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 */ } [TestClean…
[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…
Answer: [TestMethod] [ExpectedException(typeof(DivideByZeroException))] public void Divide_ByZero_ThrowsException() { var calculator = new Calculator(); calculator.Divide(10, 0); } What interviewers expect A clear defini…
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 = n…
Answer: Use the [TestCategory("CategoryName")] attribute to group tests for filtering. [TestMethod] [TestCategory("Integration")] public void IntegrationTest() { } What interviewers expect A clear definition tied to Test…
Answer: Use the [Ignore("Reason")] attribute on the test method or class. [Ignore("Test is temporarily disabled")] [TestMethod] public void SkippedTest() { } What interviewers expect A clear definition tied to Testing in…
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. What inter…
MSTest itself does not provide mocking capabilities. Use mocking libraries like Moq or NSubstitute alongside MSTest to mock dependencies. Example with Moq: var mockService = new Mock<IService>(); mockService.Setup(…
Answer: var mockService = new Mock&lt;IService&gt;(); var service = mockService.Object; // use this in your test What interviewers expect A clear definition tied to Testing in Unit Testing projects Trade-offs (pe…
Unit Testing C# Programming Tutorial · Testing
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.
In a production Unit Testing application, teams apply this when handling user-facing features or integration boundaries. For example, you might use it during a sprint where reliability and observability matter—logging metrics, validating edge cases, and documenting the decision in an ADR so future developers understand why the approach was chosen.
Tip: Practice aloud on Toolliyo mock interview or the Interview Q&A section before your real interview.
Unit Testing C# Programming Tutorial · Testing
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);
ssert.Equal(expected, result);
}Unit Testing C# Programming Tutorial · Testing
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.Unit Testing C# Programming Tutorial · Testing
Answer: Use the Skip property on [Fact] or [Theory]: [Fact(Skip = "Reason for skipping")] public void SkippedTest() { }
In a production Unit Testing application, teams apply this when handling user-facing features or integration boundaries. For example, you might use it during a sprint where reliability and observability matter—logging metrics, validating edge cases, and documenting the decision in an ADR so future developers understand why the approach was chosen.
Tip: Practice aloud on Toolliyo mock interview or the Interview Q&A section before your real interview.
Unit Testing C# Programming Tutorial · Testing
run in parallel.
[Collection("Database collection")]
public class TestClass1 { }
[Collection("Database collection")]
public class TestClass2 { }Unit Testing C# Programming Tutorial · Testing
Test fixtures provide a way to share setup and cleanup code between tests. xUnit supports:
They are implemented by creating a fixture class and injecting it into test classes via
constructor.
Unit Testing C# Programming Tutorial · Testing
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
In a production Unit Testing application, teams apply this when handling user-facing features or integration boundaries. For example, you might use it during a sprint where reliability and observability matter—logging metrics, validating edge cases, and documenting the decision in an ADR so future developers understand why the approach was chosen.
Tip: Practice aloud on Toolliyo mock interview or the Interview Q&A section before your real interview.
Unit Testing C# Programming Tutorial · Testing
constructors and IDisposable.
[InlineData].
Unit Testing C# Programming Tutorial · Testing
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); ssert.AreEqual(expected, result); }
In a production Unit Testing application, teams apply this when handling user-facing features or integration boundaries. For example, you might use it during a sprint where reliability and observability matter—logging metrics, validating edge cases, and documenting the decision in an ADR so future developers understand why the approach was chosen.
Tip: Practice aloud on Toolliyo mock interview or the Interview Q&A section before your real interview.
Unit Testing C# Programming Tutorial · Testing
Answer: [Test] public void Divide_ByZero_ThrowsException() { var calculator = new Calculator(); ssert.Throws<DivideByZeroException>(() => calculator.Divide(10, 0)); }
In a production Unit Testing application, teams apply this when handling user-facing features or integration boundaries. For example, you might use it during a sprint where reliability and observability matter—logging metrics, validating edge cases, and documenting the decision in an ADR so future developers understand why the approach was chosen.
Tip: Practice aloud on Toolliyo mock interview or the Interview Q&A section before your real interview.
Unit Testing C# Programming Tutorial · Testing
Answer: Use the [Category("CategoryName")] attribute to group tests, allowing filtering by category during test runs. [Test, Category("Integration")] public void IntegrationTest() { }
In a production Unit Testing application, teams apply this when handling user-facing features or integration boundaries. For example, you might use it during a sprint where reliability and observability matter—logging metrics, validating edge cases, and documenting the decision in an ADR so future developers understand why the approach was chosen.
Tip: Practice aloud on Toolliyo mock interview or the Interview Q&A section before your real interview.
Unit Testing C# Programming Tutorial · Testing
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.
In a production Unit Testing application, teams apply this when handling user-facing features or integration boundaries. For example, you might use it during a sprint where reliability and observability matter—logging metrics, validating edge cases, and documenting the decision in an ADR so future developers understand why the approach was chosen.
Tip: Practice aloud on Toolliyo mock interview or the Interview Q&A section before your real interview.
Unit Testing C# Programming Tutorial · Testing
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.
In a production Unit Testing application, teams apply this when handling user-facing features or integration boundaries. For example, you might use it during a sprint where reliability and observability matter—logging metrics, validating edge cases, and documenting the decision in an ADR so future developers understand why the approach was chosen.
Tip: Practice aloud on Toolliyo mock interview or the Interview Q&A section before your real interview.
Unit Testing C# Programming Tutorial · Testing
Answer: Yes, NUnit integrates seamlessly with CI/CD tools like Azure DevOps, Jenkins, GitHub ctions, and others using command-line runners or plugins, allowing automated test execution during builds and deployments. MSTest Framework
In a production Unit Testing application, teams apply this when handling user-facing features or integration boundaries. For example, you might use it during a sprint where reliability and observability matter—logging metrics, validating edge cases, and documenting the decision in an ADR so future developers understand why the approach was chosen.
Tip: Practice aloud on Toolliyo mock interview or the Interview Q&A section before your real interview.
Unit Testing C# Programming Tutorial · Testing
Answer: [TestClass] public class CalculatorTests { [TestMethod] public void Add_ReturnsSum() { var calculator = new Calculator(); var result = calculator.Add(2, 3); ssert.AreEqual(5, result); } }
In a production Unit Testing application, teams apply this when handling user-facing features or integration boundaries. For example, you might use it during a sprint where reliability and observability matter—logging metrics, validating edge cases, and documenting the decision in an ADR so future developers understand why the approach was chosen.
Tip: Practice aloud on Toolliyo mock interview or the Interview Q&A section before your real interview.
Unit Testing C# Programming Tutorial · Testing
NUnit uses [Test].
xUnit’s [Theory].
Unit Testing C# Programming Tutorial · Testing
ttributes?
[TestInitialize]
public void Setup() { /* setup code */ }
[TestCleanup]
public void Cleanup() { /* cleanup code */ }Unit Testing C# Programming Tutorial · Testing
[TestInitialize]
public void Setup() { /* setup code */ }
[TestCleanup]
public void Cleanup() { /* cleanup code */ }
Unit Testing C# Programming Tutorial · Testing
Answer: [TestMethod] [ExpectedException(typeof(DivideByZeroException))] public void Divide_ByZero_ThrowsException() { var calculator = new Calculator(); calculator.Divide(10, 0); }
In a production Unit Testing application, teams apply this when handling user-facing features or integration boundaries. For example, you might use it during a sprint where reliability and observability matter—logging metrics, validating edge cases, and documenting the decision in an ADR so future developers understand why the approach was chosen.
Tip: Practice aloud on Toolliyo mock interview or the Interview Q&A section before your real interview.
Unit Testing C# Programming Tutorial · Testing
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);
}Unit Testing C# Programming Tutorial · Testing
Answer: Use the [TestCategory("CategoryName")] attribute to group tests for filtering. [TestMethod] [TestCategory("Integration")] public void IntegrationTest() { }
In a production Unit Testing application, teams apply this when handling user-facing features or integration boundaries. For example, you might use it during a sprint where reliability and observability matter—logging metrics, validating edge cases, and documenting the decision in an ADR so future developers understand why the approach was chosen.
Tip: Practice aloud on Toolliyo mock interview or the Interview Q&A section before your real interview.
Unit Testing C# Programming Tutorial · Testing
Answer: Use the [Ignore("Reason")] attribute on the test method or class. [Ignore("Test is temporarily disabled")] [TestMethod] public void SkippedTest() { }
In a production Unit Testing application, teams apply this when handling user-facing features or integration boundaries. For example, you might use it during a sprint where reliability and observability matter—logging metrics, validating edge cases, and documenting the decision in an ADR so future developers understand why the approach was chosen.
Tip: Practice aloud on Toolliyo mock interview or the Interview Q&A section before your real interview.
Unit Testing C# Programming Tutorial · Testing
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.
In a production Unit Testing application, teams apply this when handling user-facing features or integration boundaries. For example, you might use it during a sprint where reliability and observability matter—logging metrics, validating edge cases, and documenting the decision in an ADR so future developers understand why the approach was chosen.
Tip: Practice aloud on Toolliyo mock interview or the Interview Q&A section before your real interview.
Unit Testing C# Programming Tutorial · Testing
MSTest itself does not provide mocking capabilities. Use mocking libraries like Moq or
NSubstitute alongside MSTest to mock dependencies.
Example with Moq:
var mockService = new Mock<IService>();
mockService.Setup(s => s.GetData()).Returns("Test Data");
Moq Framework (Mocking)
Unit Testing C# Programming Tutorial · Testing
Answer: var mockService = new Mock<IService>(); var service = mockService.Object; // use this in your test
In a production Unit Testing application, teams apply this when handling user-facing features or integration boundaries. For example, you might use it during a sprint where reliability and observability matter—logging metrics, validating edge cases, and documenting the decision in an ADR so future developers understand why the approach was chosen.
Tip: Practice aloud on Toolliyo mock interview or the Interview Q&A section before your real interview.