Sunday, March 25, 2012

Debugging Mochitests with Visual Studio

Debugging an xpcshell test is far straightforward when compared to the more general mochitest. In the course of fixing a bug where change events weren’t being fired for a focused and blurred text input or textrea when the user switches focus, I encountered a situation where after my initial fixes, an extra change event was then fired. To hunt down the culprit code responsible for the redundant dispatch, the current docs on debugging mochitests weren’t particularly helpful to those of us working on windows machines with Visual Studio.  This technique is largely thanks to Josh Matthews and Mark Capella:

  • Modify  testing/testsuite-targets.mk by deleting the autorun option under RUN_MOCHITEST.
  • Afterwards, run the entire mochitest suite for the branch where the particular test you want to debug is located. Wait for the browser to open with the associated tests. In Visual Studio, go to Tools->Attach Process and select the firefox.exe process showing the loaded tests.  This should switch to the debugging view.
  • Place an appropriate breakpoint in a relevant selection of the code that will most likely be triggered and then click on the link to the test that is to be debugged in the browser window.

Easy peasy lemon squeezy debugging Smile

No comments:

Post a Comment