Drill 21: Find the core line โ Testing with xUnit
Point to the line that does the main work and explain why.
What you will be able to do
- Point to the line that does the main work and explain why.
Practice task
Point to the line that does the main work and explain why.
using Xunit;
public class Calculator
{
public int Add(int a, int b) => a + b;
public int Divide(int a, int b)
{
if (b == 0) throw new ArgumentException("Cannot divide by zero");
return a / b;
}
}
public class CalculatorTests
{
private readonly Calculator calculator = new Calculator();
[Fact]
public void Add_ReturnsSum()
{
var result = calculator.Add(2, 3);
Assert.Equal(5, result);
}
[Theory]
[InlineData(6, 3, 2)]
[InlineData(9, 3, 3)]
public void Divide_ReturnsQuotient(int a, int b, int expected)
{
Assert.Equal(expected, calculator.Divide(a, b));
}
[Fact]
public void Divide_ByZero_Throws()
{
Assert.Throws<ArgumentException>(() => calculator.Divide(1, 0));
}
}Your turn
EasyWrite your answer
Point to the line that does the main work and explain why.
TEXT ยท starter
Your answerโฆStudy tools
Make it yours.
Keep a private note for this lesson, then turn the key ideas into flashcards you can revisit.
Sign in to save notes and flashcards.Both are private to your account and stay with your progress.
Sign inFinished reading?
Lock in what you just learned.
0%
Mark this lesson complete to save your place and move one step closer to the certificate.