// TDD example in ASP.NET Core
// Write a test first
public void Test_AddNumbers_ReturnsSum()
{
Calculator calculator = new Calculator();
int result = calculator.Add(2, 3);
Assert.AreEqual(5, result);
}
// Implement the code to pass the test
public class Calculator
{
public int Add(int a, int b)
{
return a + b;
}
}
// BDD example in ASP.NET Core using SpecFlow
Feature: User Registration
Scenario: Valid user registration
Given the user is on the registration page
When they fill in the registration form with valid details
And they click the registration button
Then they should see a "Registration Successful" message
// Step definitions
[Given("the user is on the registration page")]
public void GivenTheUserIsOnTheRegistrationPage()
{
// Navigate to the registration page
}
[When("they fill in the registration form with valid details")]
public void WhenTheyFillInTheRegistrationFormWithValidDetails()
{
// Enter valid registration data
}
[When("they click the registration button")]
public void WhenTheyClickTheRegistrationButton()
{
// Click the registration button
}
[Then("they should see a \"Registration Successful\" message")]
public void ThenTheyShouldSeeARegistrationSuccessfulMessage()
{
// Assert the "Registration Successful" message is displayed
}