In: Computer Science
Please write unit tests for the main method below. The unit tests must be used in MSTest for Visual Studio.
C#
//main method
public static void Main(string[] args)
{
//unsorted array
int[] dataSet = new int[5] { 2, 99, 27, 68, 3 };
//sortData method
called for sorting the above unsorted array
sortData(dataSet);
//iterating the sorted
array
for (int i = 0; i < dataSet.Length; i++)
{
//writing the sorted array to the console
Console.WriteLine(dataSet[i]);
}
}//end method
Done accordingly. Comment for further help.Please uprate.
Go to solution explorer of your project-->new-->project--> mstest project-->add reference of main project to this new project copy code and continue
Code:
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.IO;
namespace Tester
{
[TestClass]
public class UnitTest1
{
[TestMethod]
public void TestMethod1()
{
int[] dataSet = new int[5] { 2, 3, 27, 68, 99 };
String expected = "";
for (int i = 0; i < 5; i++)
{
expected = expected + dataSet[i] + "\r\n";
}
using (var sw =new StringWriter())
{
Console.SetOut(sw);
String[] x=new String[4];
TestingCode.Program.Main(x);
var result = sw.ToString().Trim();
expected= expected.ToString().Trim();
Assert.AreEqual(expected, result);
}
}
}
}