Note that there are some explanatory texts on larger screens.

plurals
  1. POConfusion between E2E testing, Unit testing and mocking data with $httpBackend
    primarykey
    data
    text
    <p>We've just started developing a web app with AngularJS and we're having some problems with testing it properly so we could use some advice. </p> <p>Generally, there are the following components to test:</p> <ol> <li>Web API</li> <li>Angular Controllers</li> <li>Angular routing</li> <li>HTML rendering and Angular binding of Controllers to the HTML elements</li> </ol> <p>How does one test all of this with minimal effort and no, if possible, overlap?</p> <p>For any database-centric application, complete integration testing (i.e. with a live server, connected to a database loaded with data) would be particularly messy because there would have to be a process that generates sufficient data for all tests and resets the DB and tests would have to be careful not to modify each other's data. (if I'm missing something here please let me know)</p> <p>Given the above point, I'm assuming it is best to sever the link between server and client and run the Angular tests using mock data only.</p> <p>Also, I'm assuming that if E2E testing takes care of all possible scenarios, unit testing controllers is redundant as their values are bound to the model (and would thus be testing all of 2, 3 and 4 above). Unit testing would only be helpful in very complex controllers or to test services and directives.</p> <p>However, we could not find any information on how to mock stuff with <code>$httpBackend</code> on a per-test basis like you would do in unit tests, using <code>expect*()</code>. Angular docs seem to suggest using <code>when*()</code> plus the occasional <code>passthrough()</code> when necessary. </p> <p>But, this poses the aforementioned problem of creating test data for all scenarios and you'd probably need to reset the in-memory DB before each test to be sure the tests are not affected. Also, you're losing the safety of using <code>$httpBackEnd.expect*()</code> which checks that there are no missing or redundant calls to the server - This would suggest to me that it would also require unit testing controllers to check this.</p> <p>Can someone provide a detailed testing strategy for AngularJS apps that addresses the testing of the 4 components above as well as the concerns written above?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload