Smart Unit Tests in Visual Studio 2015 preview

As we all of know Microsoft has introduced the new Visual Studio named Visual Studio 2015 Preview with more features for the users. Using the Microsoft Visual Studio 2015 preview Microsoft has introduced some new features that make it easier for developers to create applications. All the features play a very vital role in the development process. People say that these features provide a peek for the Visual Studio and Microsoft and I agree with them because all these features are very very powerful with many points of view as well as the developer's point of view, as well as the tester's point of view as well as a learning point of view.

All the features are shown in the figure:


Here I elaborate one of the features of Microsoft Visual Studio 2015 that is known as the Smart Unit Tests in Visual Studio 2015.

Smart Unit Tests

Smart Unit Tests means to generate the own test case depending on the needs. In a Smart Unit Test we can check every line of our code as needed. These types of codes are also known as the parameterized test cases. We can make a unit test case for every method separately or make a single unit test case for the entire class, a single class. Mostly developers do not create the Smart Unit Test Cases but if they create their own test cases then definitely these test cases will be very helpful and beneficial for them because if they do this then they can save the development time. Smart Unit Test cases create the test data for every line of code. Every time a text case occurs it is responsible for executing a specific statement. When we make test cases then we can easily determine which statement fails and which statement is successful. If there is a statement that will fail then depending on our test cases we check it and do the changes and again run it. So smart test cases are also used to find bugs easily. We cannot perform the Smart Unit Tests on unmanaged code.

The following is how to use the Smart Unit Tests in our code:






All test.
Passed test.
Failed test.












Code:

  1. using System;
  2. public class Program
  3. {
  4. public static void cal(int n1, int n2, out int addition, out int substraction, out int multiplication)
  5. // here out is a keyword which is work like a refrence parameter mostly we use the return keyword to return
  6. //the value but return keyword used only return for one value here but through the out keyword we can return the multiple value
  7. {
  8. addition = n1 + n2;
  9. substraction = n1 - n2;
  10. multiplication = n1 * n2;
  11. }
  12. static void Main(string[] args)// entry point of our program
  13. {
  14. int n1, n2;
  15. int addition, substraction, multiplication;
  16. Console.Write("Enter first number");// for entering te value
  17. n1 = Convert.ToInt32(Console.ReadLine());
  18. Console.Write("Enter second number");
  19. n2 = Convert.ToInt32(Console.ReadLine());
  20. Program.cal(n1, n2, out addition, out substraction, out multiplication);// return the value
  21. Console.WriteLine("{0} + {1} = {2}", n1, n2, addition);
  22. Console.WriteLine("{0} - {1} = {2}", n1, n2, substraction);
  23. Console.WriteLine("{0} * {1} = {2}", n1, n2, multiplication);
  24. Console.ReadLine();
  25. }
  26. }

Output



Summary

Smart Unit Tests are very helpful when you have complex code like many interfaces in a program or you are passing an interface as a parameter in a method. At that time the Smart Unit Test is very beneficial for the users because at that time we create the test case and run then manually to find the bug in our projects or in our code. Here Smart Unit Test gives the warnings or errors if it is present in the code or maybe you follow some wrong method or procedure to build a project. So finally I will say that Smart Unit Tests are a very important feature for developers in Visual Studio 2015 Preview. It makes programming and debugging easier.