How to test the upper layers of a ZF application - unit-testing

How do you test the controller and views in a Zend Framework application?
I have been using PHPUnit to test the mapper, domain and services, and that's been working fine. I use dependency injection so that I can isolate the class under test.
When it comes to the controller however I would probably not try to isolate it. I would effectively be doing integration tests at this point, but I think that's fine. I would still use PHPUnit and fire off requests for most tests.
For the views, I am thinking of using the CSS selectors in Zend_Test, but since I have a lot of Javascript I will have to use selenium too.
Does this all sound reasonable? What do you do?

Related

Do you use Jest and React Testing Library for automated tests on your react-admin app?

Do you use:
Jest
React Testing Library
I'm having a hard time figuring out what to test and how to test it. react-admin has so much based in redux and contexts that it's hard to mock those things so you're focusing on just a single component instead of testing react-admin itself.

Testing Angular and Django Rest Framework apps

Let's say I have a frontend application written in Angular and a backend application written in Django and Django Rest Framework. I created unit tests for backend application (with pytest) and I'm about to create some functional tests for the frontend application. The thing is that the frontend app needs access to the backend app in order to work correctly. I can write some mocks to handle that, but I am not sure if this is the best way to do that.
My question is, what is the best way to handle that? Should I use a single git repo for both applications or maybe a better way is to use two repositories, but then how to handle the tests for frontend application?
I was also thinking about using selenium with pytest, but then I would have to use a single repository. I am a little bit confused and would really use some good advice. Thanks!
Unit tests as the name suggests is testing separate units of the code in isolation. Meaning that it does not have to depend on any other part, else, you wouldn't know if the test is failing for that particular unit or the units it depends on.
As a result, all tests should mock the request to the backend and return valid responses (or invalid, if you're testing for error handling). The same applies to any other external service that the unit depends on.

Testing views with Spring Framework at the same time you run unit tests?

Is there a way to test views rendered in freemarker at the same time I run my unit tests? It would be great if the test failed if Freemarker threw an exception.
Rails has a feature where you can render views whenever an action is called. Is there an easy way to configure this type of behavior for Spring too?
Check out this blog post. We used this approach with great success for Velocity template. Looks like here is a working code example.
It requires few extra classes like MockWebApplicationContextLoader but works great with mocked requests.

Test Driven Development in OOP Frameworks

I recently starting learning test driven development, namely MXUnit, and I love the idea's behind it. I can understand the idea of using TDD with stand alone CFC's, but when it comes to using it with OOP based Frameworks, primarily FW/1 and CFWheels, I am not sure how to use MXUnit with the framework CFC's (controllers in FW/1 and Models and Controllers in CFWheels).
Does anyone know where I can find some resources on using MXUnit with Frameworks?
I can only talk about F/W 1 here as I have not used CFWheels (some info here in another SO question), but in my opinion framework unit testing can be simplified by proper use of a service layer.
The idea is you test service layer objects using MXUnit and leave the framework controllers (for example in FW/1) very lightweight. Essentially the controllers are just passing parameters to the service layer, getting a response back and displaying a view.
The reasoning is that the framework is the least likely place you'll introduce errors - so concentrate your testing on the service object, i.e. the core business logic of your application.
Interestingly, in other non-ColdFusion frameworks (such as Grails) the framework is not tested, tests are created for your model ('domain classes' in grails that model the data) and your service objects, but the framework is assumed to work fine. The idea there - again - is to keep logic out of your controllers and test your service layer and domain model.
I hope that helps in some way.

Is it right to only test my controllers in an MVC web app running in the Microsoft cloud and using table storage?

I'm developing a web app with MVC 2.0. I'm storing my data in Windows Azure table storage. I'm not using any mocking for my test. The test framework is the default Microsoft Unit Testing that comes with Visual Studio.
At the moment, I'm only testing my controllers: the view names that are returned, the flow when the code jumps from action to action and the view models that are sometimes returned sent to the views.
My approach isn't TDD: I write a bit of code and then I test it to make sure it passes. I'm just unit testing, not driving my development by testing first.
Am I doing the right thing with my testing: is it enough to just test the controllers?
In terms of what you should be testing, I recommend testing anything that has a branch statement and complex statements. What do I mean by that? You should be testing any code with if/else or switch statement as well as any mathematic calculations, regex, etc. For your application, this may just be your controllers, but may include views, models or any other classes that you have written. Its not uncommon for view models or domain models to contain code that should be tested.