I am building a web application in php. I am following TDD (write tests before production code) for my unit tests and using BDD to drive discovery of my applications features and to provide integration tests.
My architecture is based around Robert Martins Clean Architecture where by I have application use case classes / interactors that form the primary classes of my application.
My BDD steps call the application use case classes directly to drive the application. TDD tests are written before any new line of code and provides unit tests for all classes. With these two development methods, I have full test coverage of my application for integration and unit tests.
The problem I have run into is that whilst I have tested everything in the application, and confirmed all required features have been implemented, what I don't have is a nice Web Application UI which a user can use. Currently the only users who can use the application are developers who would need to call the application use case classes directly. For developers, the code base is 100% covered by unit tests (TDD) and integration tests (BDD).
What I need to do now is create a browser application that will call URIs. These URIs will be linked to the application use cases. Like any modern day browser application, the browser application will call multiple URIs asynchronously to provide a rich user experience.
My question is: How do I test this part of my code base? This isn't a question about which tool to use (although recommendations would be welcomed) but more at what level should I test? I guess this question could also be written as
'I am a front end developer creating a front end web app using a library or web service that has been created by another developer. How should I test my app?'
My two thoughts are:
- Test the browser application and associated URIs but mock out the application use cases that are called by the controllers
- Leave the controllers call the real application use cases and in effect provide another level of integration tests / end to end tests with the addition of the web delivery layer (browser application and URIs)
The problem I see with 1) (as with any tests where mocks are involved) is that if I incorrectly mock the requests and responses for that application use cases, there will be no tests to pick this up and bugs will pop up once everything is integrated together.
This then leads to the obvious answer that we should test with more integration using 2). The issue I have with this is that I feel I will now be duplicating a lot of integration tests and testing will be very slow.
Im also not sure what level of tests I should write. Should I write large, user acceptance test that take a number of different use cases combined together? e.g. test that a product can be added to a store, purchased by a customer and then shipped. Or should I test each application UI view on its own? e.g. customer can view product for purchase.