Github Webapps MochiTest Repo

Writing your First MochiTest:

Can be a daunting task, all this mozilla code, all these strange words, mochitest, mozilla-central, jumping into the code base.. All are daunting tasks, but hopefully this tutorial will walk you through the general process.

Learn by Example:

The example that I am going to show is the soon to be performed work on mozilla central to port the webapps extension into the mozilla code base.

The exciting part about this we get to test against code that hasn’t been written.  The codebase i want to test will eventually be on mozilla central , but is currently not.  I didn’t select the option of testing against a debug build, because we might actually want to test against patches to the codebase. (which is what we are doing)

Building Firefox:

https://developer.mozilla.org/En/Developer_Guide/Build_Instructions

MochiTest Basics:

https://developer.mozilla.org/en/Mochitest

Assuming you have built mozilla central and you are able to run MochiTests, then what next.Well firstly you will want to choose a location for your tests.

Now If you are working on webapps this directory might be: dom/tests/mochitest, as it looks as a lot of tests that are dom related lie there. For each project it will be different, and you may want to seek out different opinions as to where things might go.

You will then have to create a directory “webapps”, and edit Makefile.in and add your directory below

DIRS  += \
dom-level0 \
dom-level1-core \
dom-level2-core \
dom-level2-html \
webapps \
storageevent \
$(NULL)

Next step would be to create a Makefile.in inside your directory foobar.  Below is a github commit by Geo Mealer which establishes our base repository.

Github Webapps MochiTest Repo

Running your Dummy Test Case:

navigate to the top directory in your mozilla-central codebase

TEST_PATH=dom/tests/mochitest/webapps/test_dummy.html make -C obj-ff-dbg/ mochitest-plain

Level II on your path:

Next you will be forced to consider / raise several issues with your development team.

You will want the ability to pref off certain chrome elements.

Determining what those prefs are that accomplish the goal is a conversation that needs to happen with the development team.!

It’s best to hold off writing until you have a general agreement, about this piece.

  •  Designing your test framework.

Mochitests are a simple html / js test framework, it uses simple expressions like “is”, “is_not”, “ok”.  So the real difficulty is in designing your test framework to get the results you need.  Sometimes you will need greater access to objects other than prefs, sometimes you will need access to specific data structures to retrieve and set information.

There are tons of examples in the mochitest framework to work with:

localStorage, geolocation, general all have good examples. It really depends on what you are attempting to do, and how much effort you want to expend.

  • Webapps Test Run

The test fails because the code isn’t implemented.  This codebase is a part of the same repo, but in a branch entire suite btw 🙂 TDD. 🙂

 

Advertisements

One thought on “Github Webapps MochiTest Repo

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s