Test-Driven Development workflow and testing standards...
Apply Test-Driven Development methodology to ensure reliability and confidence when adding new features.
Follow this cycle for all new features:
Frontend (JavaScript/TypeScript)
Backend (C#/.NET)
Test Naming Convention
shouldDoSomethingWhenCondition()
// Arrange - Set up test data and conditions
// Act - Execute the code being tested
// Assert - Verify the results
import { describe, it, expect } from 'vitest'
import { calculateTotal } from './cart'
describe('calculateTotal', () => {
it('shouldReturnZeroWhenCartIsEmpty', () => {
// Arrange
const cart = []
// Act
const total = calculateTotal(cart)
// Assert
expect(total).toBe(0)
})
it('shouldCalculateTotalWithMultipleItems', () => {
// Arrange
const cart = [
{ price: 10, quantity: 2 },
{ price: 5, quantity: 3 }
]
// Act
const total = calculateTotal(cart)
// Assert
expect(total).toBe(35)
})
it('shouldThrowErrorWhenItemHasNegativePrice', () => {
// Arrange
const cart = [{ price: -10, quantity: 1 }]
// Act & Assert
expect(() => calculateTotal(cart)).toThrow('Price cannot be negative')
})
})
using Xunit;
public class CartCalculatorTests
{
[Fact]
public void ShouldReturnZeroWhenCartIsEmpty()
{
// Arrange
var cart = new List<CartItem>();
var calculator = new CartCalculator();
// Act
var total = calculator.CalculateTotal(cart);
// Assert
Assert.Equal(0, total);
}
[Fact]
public void ShouldCalculateTotalWithMultipleItems()
{
// Arrange
var cart = new List<CartItem>
{
new CartItem { Price = 10, Quantity = 2 },
new CartItem { Price = 5, Quantity = 3 }
};
var calculator = new CartCalculator();
// Act
var total = calculator.CalculateTotal(cart);
// Assert
Assert.Equal(35, total);
}
[Fact]
public void ShouldThrowExceptionWhenItemHasNegativePrice()
{
// Arrange
var cart = new List<CartItem> { new CartItem { Price = -10, Quantity = 1 } };
var calculator = new CartCalculator();
// Act & Assert
Assert.Throws<ArgumentException>(() => calculator.CalculateTotal(cart));
}
}
Following this workflow ensures:
Apply TDD when: