Every repository with this icon (
Every repository with this icon (
Unit Testing
SproutCore comes with an in-browser JavaScript unit testing harness.
You can run SproutCore’s own unit tests with the harness at any time. This is a good idea if you’re trying out SproutCore in a new browser, or you suspect SproutCore itself might have a bug.
NOTE: The examples in this page assume you have already installed SproutCore and are running
sc-server. You will need to change the name ofmy_appin URLs and commands to the name of your own SproutCore application.
Run SproutCore’s own unit tests in a web browser
http://localhost:4020/sproutcore/-tests
Initially, the top unit test runs. The status of all tests should be “passed”. If not, SproutCore has a bug in your browser.
Report a SproutCore unit test failure
You should report SproutCore unit test bugs immediately at http://sproutit.lighthouseapp.com/. Be sure to include:
- the test that failed
- the browser name and version (e.g. FireFox 3.1.0.96.56 beta 82)
- the platform and version (e.g. Windows XP SP3)
- the version of SproutCore you ran the test with (e.g. SproutCore 0.9.9)
To see what version of SproutCore you are running, do:
$ sproutcore -v sproutcore 0.9.9The result is printed to the command line.
Run the entire SproutCore unit test suite
To check the rest of SproutCore’s unit tests, click the “Run All Tests” button in the upper-right corner. (Leave the “Continuous Integration” checkbox off for now.)
SproutCore will load each test into the browser in-turn and run it. Any errors will show up in red. If you get an error, you know what to do: file a bug report at http://sproutit.lighthouseapp.com/.
You can run any individual test by clicking on the test in the left pane. As you may have guessed, you can also create unit tests for your own code.
Run unit tests for your SproutCore application in a web browser
http://localhost:4020/my_app/-tests
You should get a dialog box that says: “App has no tests.” That makes sense, since we haven’t added any tests. Let’s add one now.
Create a new unit test and run it
$ sc-gen test my_app/test_unit_testReload http://localhost:4020/my_app/-tests. Your new test should show up and run automatically (since it is the only test). The test should pass.
Enable continuous integration
Go ahead and check the “Continuous Integration” checkbox. Then press the “Run All Tests” button. You should see your unit test run continuously, again and again. If you had more than one unit test, they would each run in turn, in a loop.
Let’s introduce a failure. Open apps/my_app/tests/test_unit_test.rhtml. It should look like this:
<pre><% # ========================================================================
- Test Unit Test Unit Test
- ================
>
< content_for(‘final’) do %>
<% end %>
Change line 12 to read:
true.shouldEqual(false) ;Save the file and return to your browser. You should see a red, failed unit test and a JavaScript alert dialog that says “Unit Test Failed!”. Go ahead and press the “OK” button to dismiss the alert dialog.
The unit tests are now stopped on the failed test, even though “Continuous Integration” is still checked. Go back and change the false back to true. Be sure to save the file again. Now press the “Rerun Current Test” button in the bottom-right corner of the browser.
The test should pass. Observe that even though we have “Continuous Integration” checked, the tests still aren’t running continuously yet. For that, you would need to re-press the “Run All Tests” button in the upper-right corner to start the loop again.
NOTE: SproutCore uses the same library as script.aculo.us for unit testing. You can learn more about it here.
Related Links
- Script.aculo.us Unit Testing Documentation – Documentation for the unit testing library included with SproutCore.
Comments
Example comment from Charles. – sproutit






