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

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.