25

I am having a problem with QUNIT, no matter what I seem to do the test suites will only ever recognize one test or module, even though I have multiple one's in the javascript. Any help will be greatly appreciated!

    <script>
          $(document).ready(function(){
            QUnit.log = function(result, message)
            {
                if (window.console && window.console.log)
                {
                   window.console.log(result +' :: '+ message);
                }   
            }
            module("Basic Unit Test");
            test("Sample test", function()
            {
                expect(1);
                equal(divide(4,2),2, 'Expected 2 as the result, result was ' + divide(4,2));
            });
                        test("Test two", function() {
                        expect(1);
                        equal(divide(8,2),2,'Expected 4 as the result, result was ' + divide(8,2));
                        });

            function divide(a,b){
                return a / b;
            }
          });

    </script>
scalabilitysolved
  • 2,498
  • 1
  • 24
  • 29

3 Answers3

72

You probably have QUnit-Url-Parameters in the Url which restrict testing to the modules / tests specified in these filter params (on http://docs.jquery.com/Qunit see "URL Parameters"). Start with a clean URL and then all your tests should be executed.

eg. Your URL contains blah.html?testNumber=1. This means only one test will run. Remove ?testNumber=1.

ashes999
  • 9,462
  • 13
  • 66
  • 117
Dietmar Koenig
  • 736
  • 5
  • 3
28

Earlier when you were setting it up, you clicked on "Rerun". This quietly added a "?testNumber=1" to your URL that excludes all other tests from being run.

Frustrating how quiet that is.

sirbrialliance
  • 3,432
  • 1
  • 25
  • 15
  • 4
    Thank you, thank you, THANK YOU for a clear, precise answer. This has been killing me for 20 minutes! – Ted A. Apr 24 '13 at 23:30
  • Was frustrating but became interesting once I started playing with the numbers ?testNumber=1,2,3... Interestingly it only executes the particular test case with whatever number I pass :) Thanks a lot for the answer. – Anmol Saraf Sep 20 '13 at 00:22
3

Here is a sample page that will run more then one test

It contain the two tests you put here.

Ido Green
  • 2,771
  • 1
  • 14
  • 24