I have an application design that looks like this:
So my data layer is completely transparent to data model implementation because upper layer don't use data entities at all.
As much as I understand unit, integration and system testing (with relation to Asp.net MVC) is this:
I can easily see how to write unit tests as well as system tests, but I don't know how to write integration tests? Maybe my view of these is completely distorted and I don't understand them at all.
How should one write integration and system tests for an Asp.net MVC application?
Or any .net application for that matter?
Suppose I have classes like:
TaskController
calls into TaskService
TaskService
calls into TaskRepository
TaskRepository
manipulate EF data internallySo here are my (abbreviated) classes:
public class TaskController
{
private ITaskService service;
// injection constructor
public TaskController(ITaskService service)
{
this.service = service;
}
// default constructor
public TaskController() : this(new TaskService()) {}
public ActionResult GetTasks()
{
return View(this.service.GetTasks());
}
...
}
public class TaskService : ITaskService
{
private ITaskRepository repository;
// injection constructor
public TaskService(ITaskRepository repository)
{
this.repository = repository;
}
// default constructor
public TaskService() : this(new TaskRepository()) {}
public IList<Task> GetTasks()
{
return this.repository.GetTasks();
}
...
}
public class TaskRepository : ITaskRepository
{
public IList<Task> GetTasks()
{
// code that gets tasks from EF and converts to Task POCOs
}
...
}
Unit test is simple and would look like this:
public void UnitTest()
{
var mock = new Mock<ITaskService>();
// other code that mocks the service
TaskController controller = new TaskController(mock.Object);
// do the test
}
But when it comes to an integration test, how do I mock only certain parts of the integration.
public void IntegrationTest()
{
// no mocking at all
TaskController = new TaskController();
// do some testing
}
First of all I can't just mock database here? I could mock repository and have real service and controller though...
4 Levels of Testing Unit Testing : checks if software components are fulfilling functionalities or not. Integration Testing : checks the data flow from one module to other modules. System Testing : evaluates both functional and non-functional needs for the testing.
Unit Testing is a kind of white box testing, whereas Integration Testing is a kind of black-box testing. For Unit Testing, accessibility of code is required, as it tests the written code, while for Integration Testing, access to code is not required, since it tests the interactions and interfaces between modules.
Integration tests should test the integration between components. While unit tests test individual pieces of a single component, integration tests the interactions between components, and are meant to work live. So an integration test would utilize a database and any other external dependencies, where its best to mock these services in unit testing.
System test to me would be functional testing (another level of testing using something like fit), or ui testing through a tool like testcomplete or telerik's QA tool.
HTH.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With