Task is to write unit tests for testing the KwHpConverter method. It is possible to use the software framework as desired. It is necessary to define a larger number of test cases and try to find a test case that will end in failure. Errors that you detect in the testing process need to be corrected. Here is code an methode:
namespace MyApp
{
class Program
{
static void Main(string[] args)
{
double result = 0;
Console.WriteLine("Please, enter value: ");
double value = double.Parse(Console.ReadLine());
Console.WriteLine("Convert to (enter kw or hp(sad)");
string convertTo = Console.ReadLine();
if(convertTo == "kw")
{
result = KwHpConverter(value, "kw");
} else
{
result = KwHpConverter(value, "hp");
}
Console.WriteLine(result);
}
private static double KwHpConverter (double inputValue, string convertTo)
{
if(convertTo == "hp")
{
return inputValue / 0.745699872;
} else
{
return inputValue * 0.745699872;
}
}
}
}
Satya KarkiPosted Feb 1, 2022, 6:53 AM
Hi, you can use any available framework such as MS Test, Xunit, NUnit and write the test cases and execute all tests at once, and also can see the errors and failed test cases. You can get an idea following the below articles on how to create a test project and write test cases:
https://www.c-sharpcorner.com/article/how-to-write-unit-test-for-exception-and-console-log-in-c-sharp/
https://www.c-sharpcorner.com/article/a-basic-introduction-of-unit-test-for-beginners/
Muhammad Imran AnsariPosted Jan 31, 2022, 8:13 PM
Shweta LodhaPosted Jan 31, 2022, 6:22 PM