Testing on the Toilet

October 2, 2008

Simulating Time in jsUnit Tests Sometimes you need to test client-side JavaScript code that uses setTimeout() to do some work in the future. jsUnit contains the Clock.tick() method, which simulates time passing without causing the test to sleep. For example, this function will set up some callbacks to update a status message over the course of four seconds: function showProgress(status) { status.message = "Loading"; for (var time = 1000; time <= 3000; time+= 1000) { // Append a '.' to the message every second for 3 secs. setTimeout(function() { status.message += "."; }, time); } setTimeout(function() { // Special case for the 4th second. status.message = "Done"; }, 4000); }

The jsUnit test for this function would look like this: function testUpdatesStatusMessageOverFourSeconds() { Clock.reset(); // Clear any existing timeout functions on the event queue. var status = {}; showProgress(status); // Call our function. assertEquals("Loading", status.message); Clock.tick(2000);

// Call any functions on the event queue that have been // scheduled for the first two seconds. assertEquals("Loading..", status.message); Clock.tick(2000); // Same thing again, for the next two seconds. assertEquals("Done", status.message); }

This test will run very quickly - it does not require four seconds to run. Clock supports the functions setTimeout(), setInterval(), clearTimeout(), and clearInterval(). The Clock object is defined in jsUnitMockTimeout.js, which is in the same directory as jsUnitCore.js.

More information, discussion, and archives: http://googletesting.blogspot.com Copyright © 2007 Google, Inc. Licensed under a Creative Commons Attribution–ShareAlike 2.5 License (http://creativecommons.org/licenses/by-sa/2.5/).

Simulating Time in jsUnit Tests

Oct 2, 2008 - Sometimes you need to test client-side JavaScript code that uses ... Clock.reset(); // Clear any existing timeout functions on the event queue.

144KB Sizes 2 Downloads 208 Views

Recommend Documents

Simulating Time in jsUnit Tests
Oct 2, 2008 - Sometimes you need to test client-side JavaScript code that uses setTimeout() to do some work in the future. jsUnit contains the Clock.tick() method, which simulates time passing without causing the test to sleep. For example, this func

Time in jsUnit Tests Code
Mar 29, 2007 - function testUpdatesStatusMessageOverFourSeconds() {. Clock.reset(); // Clear any existing timeout functions on the event queue. var status = ...

Nonparametric Tests of the Markov Hypothesis in Continuous-Time ...
Dec 14, 2010 - Princeton University and NBER, Princeton University and University of .... Under time-homogeneity of the process X, the Markov hypothesis can ...

Simulating Frontotemporal Pathways Involved in ... - eScholarship
experimental manipulations. The current ..... Using this simulated manipulation of frequency and context, we .... IEEE International Joint Conference on Neural ...

Simulating Frontotemporal Pathways Involved in ...
storing new words should be addressed by a quick automatic process. .... interpretation is generated online by adding neurons between the TL and LIFG, and .... to the same degree interactions between several brain regions that have been ...

Simulating the Human Brain - Cordis
Understand the brain at all levels of organization (genes to whole brain); simulate the brain ... Build software applications to model, simulate, visualize and diagnose biologically ... ICT methods for pharmaceutical companies. (disease and drug ...

Simulating the Human Brain - Cordis
Build a suite of analytics applications to process brain data. (signal analytics, visual analytics, real-time analytics, auto- analytics); build data display applications ...

Simulating Adaptive Communication
N00014-95-10223 to John Anderson at Carnegie Mellon University. ..... In fact, even when given explicit instructions that the computer could not ...... Computer Science and Engineering, Oregon Graduate Institute of Science & Technology.

Simulating Reach Motions
technique to fit polynomial equations to the angular displacements of each ... A description of current research on human motion simulations at the University of.

Simulating Computational Societies
and implementors, this can be used to model, analyse and explain the .... model and the software developed to facilitate experimentation with agent so-.

Simulating a two dimensional particle in a square quantum ... - GitHub
5.3.12 void runCuda(cudaGraphicsResource **resource) . . . . . 17 ... the probabilities of the position and the energy of the particle at each state. ..... 2PDCurses is an alternative suggested by many http://pdcurses.sourceforge.net/. The.

Simulating the Ionosphere - GitHub
Sep 30, 2009 - DEFINITION: Approximating measurements at intermediate scales/positions from scattered measurements. We have sparse measurements.

Refactoring Tests in the Red
Apr 25, 2007 - With a good set of tests in place, refactoring code is much easier, as you can quickly gain a lot of confidence by running the tests again and ...

"A Finite Element Model for Simulating Plastic Surgery", in - Isomics.com
mathematical model of the physical properties of the soft tissue. ... a skin and soft-tissue computer model would allow a surgeon to plan ... Mechanical analysis.

Simulating the Adaptive Behaviour of Storytellers in Computer Video ...
tive entertainment, and in computer video games in particular. ... ment (which amount to directing a virtual avatar to take various actions or speak certain lines of ...

Simulating the Adaptive Behaviour of Storytellers in Computer Video ...
tive entertainment, and in computer video games in particular. Computer ... This paper contains some text from a current demonstration submission to AIIDE'08.

Simulating Stochastic Differential Equations and ...
May 9, 2006 - This report serves as an introduction to the related topics of simulating diffusions and option pricing. Specifically, it considers diffusions that can be specified by stochastic diferential equations by dXt = a(Xt, t)dt + σ(Xt, t)dWt,

Gaming and Simulating EthnoPolitical Conflicts
is an editable list of norms/value systems from which each group's identity is drawn. The range across .... and cultural norms (Hermann, 1999), plus the additions of protocol vs. substance, and top level ..... Lsim Legend: Blue = Leader and Cops/Arme

Simulating Reflector Antenna Performance with GRASP9 - GitHub
Surfaces. – conic sections (e.g. parabolas, ellipsoids, etc.) – point cloud (e.g. shaped surface). – planes. – struts. – surface with errors. • Rim defined separately.

simulating anisotropic frictional response using ...
The most common treatment of anisotropic friction in the literature assumes an ...... never outside the slip surface, therefore there are always two real solutions for ...

Simulating Adaptive Communication
Keywords: ACT-R, modeling, communication, accommodation, efficiency .... Summary . ..... dialogue acts can be initiated with the Request and Assess buttons.

Simulating History: The Problem of Contingency - CiteSeerX
Analyses of Social Issues and Public Policy, Vol. 3, No. 1, 2003. Simulating History: The Problem of Contingency. David R. Mandel∗. University of Victoria.

PDF Forecasting and Simulating Software ...
PDF Forecasting and Simulating Software. Development Projects: ... Toolbox for the Agile Coach - Visualization Examples, How great teams visualize their work.