lpjk
lpjk

Reputation: 33

how to unit test the following code

I'm currently stuck on trying to create a unit test for the following code;

using System;

namespace EuroMonitorTest
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            int answer = 5;

            Console.WriteLine("Please enter a number less then 5");
            int value = Convert.ToInt32(Console.ReadLine());

            if (value <= answer)
            {
                Console.WriteLine("The number required to get to  5 is " + (answer - value));
            }
            else if (value > answer)
            {
                Console.WriteLine("That number is over 5, Try Again");
            }

            Console.ReadKey();
        }
    }
}

Upvotes: 0

Views: 82

Answers (1)

Alexis Garon-Michaud
Alexis Garon-Michaud

Reputation: 54

you might consider to extract the logic to a seperate class. For exemple, you could create a class that receive a "value input" and an "answer input" + a method that return a string. It will help you separate the reponsabilities of your program.

look at this link : http://haroldrv.com/2015/02/using-test-driven-development-tdd-to-solve-fizzbuzz/

Upvotes: 1

Related Questions