Testing large application with karma that has around 2000 tests

1,810 views
Skip to first unread message

Igor Bulovski

unread,
Nov 28, 2014, 3:08:04 AM11/28/14
to ang...@googlegroups.com
Hi all, 

I want to ask for a guideline or some tips of how to correctly write large number of unit tests. Currently we have around 1800 tests and that numbers increases every day. 
Majority of the tests are testing directives and services. Some of the directives renders whole panels and so on.

When we run the tests on Chrome , memory goes up to around 850 MB and they are starting to execute slow and after some period browser is disconnected.
If we switch to Firefox, then test are passing, because Firefox doesn't have a memory limit per tab (as chrome has), but that is temporary solution.
Obviously we have some memory leak or we don't do proper clean up after the test.

About our tests and set up:
  • We use :
    • angularJS: 1.3.2
    • grun-karma: 0.8.2 
    • jasmine
  • Each test is defined in own file (.spec.js)
  • We have general helper file that has :
    • beforeEach when we set up some mock for all of the tests.
    • afterEach when we try to clean up :
      • compiled element with dealoc function (copied from anguilarJS source)
      • clean $rootScope and $rootElement (also copied from angularJS source)
I created small plunker which has non-runnable example of how our test are structured :
 - http://plnkr.co/edit/F8qOdwkaXNJK9ZHhfFEl

Currently we are investigating to see why our test take that much of memory (memory leak). Our application works fine without consuming memory at all.

If anyone had some similar problem or some tips like how to clean up, what not to use in test (like mock ngModelController) or any idea, please share to us.

Thanks in advance,
Igor

Robert Abbott

unread,
Aug 13, 2015, 12:56:11 PM8/13/15
to AngularJS
Wondering if you ever found a solution to this problem. I am currently running into the same thing, and looking for tips as well.

Our tests are setup in a similar manner as yours, using the afterEach to try to perform the cleanup & we are at about 3k tests.

Thanks.

Igor Bulovski

unread,
Nov 16, 2015, 9:30:13 AM11/16/15
to AngularJS
Hi, 

One team member in our team found the solution.

Problem is that we don't do proper cleaning for global variables in each describe block.

We will try to push this information to AngularJS docs page for writing unit tests.

Best regards,
Igor

Michael Smuin

unread,
May 5, 2016, 11:44:37 PM5/5/16
to AngularJS
Is this going to be the recommended practice in unit tests? Are there any plans to update the AngularJS documentation to reflect this? Another solution is found at http://blog.thecodecampus.de/avoid-memory-leaks-angularjs-unit-tests/

If the AngularJS documentation had been changed to reflect this, our team would not have run into the same problem. If this is to be a best practice, might there also be necessary steps that have to be taken with AngularJS2 unit tests as well using TypeScript to minimize memory leaks produced by unit tests? Given the desire to write unit tests for our code, running into these kinds of limitations with a very large code base is not desirable.

Thanks
Reply all
Reply to author
Forward
0 new messages