0

I am learning about unit testing using the NUnit framework.

I built a monopoly game in a console application and am now conducting unit tests for each class.

I am struggling with writing a test for my game class that only takes 1 method:

public abstract class Game: GameInterface
    {
        private int playersCount;

        public abstract void initializeGame();
        public abstract void makePlay(int player);
        public abstract bool endOfGame();
        public abstract void printWinner();

        // A template method : 
        public void playOneGame(int playersCount)
        {
            this.playersCount = playersCount;
            initializeGame();
            int j = 0;
            while (!endOfGame())
            {
                makePlay(j);
                j = (j + 1) % playersCount;
            }
            printWinner();
        }
    }

How could I write a test for this using the NUnit framework??

Thankyou

2
Contributors
1
Reply
6
Views
2 Years
Discussion Span
Last Post by rubberman
0

Since Game is an abstract class, you need to create a concrete class derived from it without the playOneGame method, and then instantiate it, and run that method, testing the output from a number of inputs. You will have to implement the abstract methods declared in the Game class.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.