Search code examples
asp.net-mvcunit-testingautomated-testsnunitdata-driven-tests

Automation Testing with a set of data from an external source in Visual Studio 2017


I have built an application using Asp.Net MVC. Application is almost completed and now it is in testing phase.

Is it possible to create automation testing using visual studio 2017 and generate report for the same ?

Let me explain here...

suppose I have a user registration page and admin needs to enter user details ( First Name,Last Name , user name , email , phone etc.).

  1. can I create a test case for that page and automate the testing ?
  2. Is it possible to feed a set of input data like n number of records from an external source ( excel , csv) and test for each record.
  3. And finally is it possible to generate report for that particular test case ( again for each record ) ?

I have unit test project for the MVC project and I am using nunit here. But not sure how to achieve this requirement using unit testing. Any help will be appreciated.

Thanks in advance.


Solution

  • Yes, you can create a test which will test your method. Let's consider different variants.

    1. If you want to run a test and run your ASP.Net MVC application and auto-populate all fields. You could use Selenium framework and create automation test(s).
    2. You want to create classic NUnit test with parameters. In this case, I would recommend use [TestCase] attribute. Where you can specify different various of parameters. If you want to retrieve your data from the external source you can create some kind of loader. Where firstly you will read the external source and create a list of your objects. Then you will mark your method with [TestCaseSource] attribute. You will create a class which will be a source of your method.
    3. If you want to run unit tests only for some area you can organize your tests in a different group. You can use [TestCategory] attribute for this propose.

    Useful links:

    1. https://testingbot.com/support/getting-started/nunit.html
    2. https://github.com/nunit/docs/wiki/TestCaseSource-Attribute
    3. https://msdn.microsoft.com/en-us/library/dd286683.aspx