This repository has been archived by the owner on Apr 27, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 96
Testing
Steve McKay edited this page Oct 22, 2013
·
2 revisions
Provided that you inject a tracker instance where it is needed (as opposed to cooking one up directly in your code) you can supply a tracker object specially configured to support different testing goals.
# Use the same tracker implementation used by the library at runtime.
# Most business logic lives in the various Channel implementations.
analytics.internal.ServiceTracker
# Use a DummyChannel if you want to drop all hits on the floor.
analytics.internal.DummyChannel
# Use TestChannel if you want to make asserts about the hits your code sends.
analytics.testing.TestChannel
If you just don't want hits from your tests to be sent to the GA servers use DummyChannel:
var tracker = new analytics.internal.ServiceTracker(
new analytics.internal.DummyChannel());
var myClass = new MyClass(tracker);
If you want to make asserts about hits your class is sending you can use the TestChannel:
var channel = new analytics.testing.TestChannel();
var tracker = new analytics.internal.ServiceTracker(channel);
var myClass = new MyClass(tracker);
Then do stuff that cases hits to be sent, and finally make asserts about them:
tracker.assertHitSent(hit);
tracker.assertNumHitsSent(n);
# there are other handy asserts on this object.
Neither DummyChannel or TestChannel ever sends any hits to GA servers.
NOTE: All of the classes in the "analytics.internal" package are obfuscated in the release bundle, so you'll need to build/run tests from the uncompiled sources.