Question What do i have to make this Code Testable

LPYoshi

New member
Joined
Sep 16, 2022
Messages
1
Programming Experience
Beginner
Hey guys,
so i'm sitting here actually for hours now trying to figure out, how i can make my Code testable, i'm pretty new to C# so i don't have really any knowledge and would appreciate some help!
So this is my current code. My Instructor told me that i have to create a new Method that is testable with an unit test but i cant figure out how i'm supposed to do this :(.
C#:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace fisbas
{
    public class Program
    {
        static void Main(string[] args)
        {
            int fis;
            int bas;
            Console.WriteLine("Type in the Value for Fis:");
            int.TryParse(Console.ReadLine(), out fis);
            Console.WriteLine("Type in the Value for Bas:");
            int.TryParse(Console.ReadLine(), out bas);
            FisBasRechner(fis,bas);

        }
        public static void FisBasRechner(int fis, int bas){
            for (int i = 0; i <= 100; i++)
            {
                if ( i % fis == 0 && i % bas == 0)
                {
                    Console.WriteLine("FisBas");
                }
                else if ( i % fis == 0)
                {
                    Console.WriteLine("Fis");
                }
                else if ( i % bas == 0)
                {
                    Console.WriteLine("Bas");
                }
                else
                {
                    Console.WriteLine(i);
                }    
            }
            Console.ReadLine();
        }
    }
}
 
Last edited by a moderator:

Skydiver

Staff member
Joined
Apr 6, 2019
Messages
5,698
Location
Chesapeake, VA
Programming Experience
10+
Unit tests have no user interaction. Your current method requires user interaction to provide input and see the results.
 
Top Bottom