I have a question related to unit tests. I have MVC controller in which i have different actions and i want to write unit tests on all actions.I have written unit tests on classes/functions using NUnit and VS Unit Test framework but Can you recommend any framework to write unit tests on controller actions?
-
The same combo should be good enough for your scenario, tooAlex Marculescu– Alex Marculescu2016-07-06 13:13:47 +00:00Commented Jul 6, 2016 at 13:13
-
Creating Unit Tests for ASP.NET MVC ApplicationsNkosi– Nkosi2016-07-06 13:14:21 +00:00Commented Jul 6, 2016 at 13:14
-
Questions asking us to recommend or find a book, tool, software library, tutorial or other off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.Lexi– Lexi2016-07-06 14:02:27 +00:00Commented Jul 6, 2016 at 14:02
Add a comment
|
1 Answer
Referencing Creating Unit Tests for ASP.NET MVC Applications (C#)
From what you have already stated you should be able to use the tools that you already have NUnit and VS Unit Test framework
For example
[Test]
public void TestDetailsViewData()
{
var controller = new ProductController();
var result = controller.Details(2) as ViewResult;
var product = (Product) result.ViewData.Model;
Assert.AreEqual("Laptop", product.Name);
}
1 Comment
Ehsan Hafeez
Let me check it, Thanks Nkosi