Welcome to my blog!

Unit Testing with xUnit

January 22, 2018 14:37



public enum CardValue { Two = 2, Three, Four, Five, Six, Seven, Eight, Nine, Ten, Jack, Queen, King, Ace }

public enum CardSuit { Spades, Diamonds, Clubs, Hearts }


public class Card
    public Card(CardValue value, CardSuit suit)
        Value = value;
        Suit = suit;

    public CardValue Value { get; }
    public CardSuit Suit { get; }

    public override string ToString() => $"{Value} of {Suit}";


using Xunit;

namespace PetProject1.UnitTest
    public class CardTests
        public void CanCreateCardWithValue()
            var card = new Card(CardValue.Ace, CardSuit.Spades);

            Assert.Equal(CardSuit.Spades, card.Suit);
            Assert.Equal(CardValue.Ace, card.Value);

        public void CanCreateDescribeCard()
            var card = new Card(CardValue.Ace, CardSuit.Spades);

            Assert.Equal("Ace of Spades", card.ToString());


Install-Package xUnit
Install-Package xUnit.Runner.VisualStudio
Install-Package FluentAssertions

Unit Test Explorer

Test > Windows > Test Explorer

ReSharper > Unit Tests > Unit Tests


Unit Test

June 29, 2017 18:42

Kiếm thử phần mềm


Unit-Test Patterns for .NET





Arrange-Act-Assert (AAA) Pattern

  • Arrange
  • Act
  • Assert

Writing Unit Tests for the .NET Framework with the Microsoft Unit Test Framework for Managed Code


The AAA (Arrange, Act, Assert) pattern is a common way of writing unit tests for a method under test.

  • The Arrange section of a unit test method initializes objects and sets the value of the data that is passed to the method under test.

  • The Act section invokes the method under test with the arranged parameters.

  • The Assert section verifies that the action of the method under test behaves as expected.


Recent posts