@manhnguyenv

Welcome to my blog!

Unit Testing with xUnit

January 22, 2018 14:37

PetProject

----------------------------------------------------------------------------------------------------

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
    {
        [Fact]
        public void CanCreateCardWithValue()
        {
            var card = new Card(CardValue.Ace, CardSuit.Spades);

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

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

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

PetProject.UnitTest

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

https://anhtuanzinto.wordpress.com/category/unit-test/

Unit-Test Patterns for .NET

https://www.typemock.com/unit-test-patterns-for-net/

https://www.typemock.com/unit-test-patterns-part-ii/

https://www.typemock.com/unit-test-patterns-part-iii/

 

Arrange-Act-Assert (AAA) Pattern

  • Arrange
  • Act
  • Assert

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

https://msdn.microsoft.com/en-us/library/hh598960.aspx

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.

Categories

Recent posts