EzDevInfo.com

Pavlov.js

Reinforcement learning using Markov Decision Processes

Index out of range error using Chutzpah's Visual Studio extension

I think there aren't a lot of Chutzpah users out there currently, but hopefully I will find some on here.

I am working up a demo of Pavlov so I can contrast it to traditional QUnit tests and show my team the advantages of BDD. I stumbled over Chutzpah along the way and thought it would be really cool to integrate into my project.

When I right click and run the tests in my browser, they both work fine, but if I right click and run the tests in VS, I get this error:

------ Test started: File: C:\Users\U0120711\Documents\Visual Studio 2010\Projects\Behave\StaticContent\tests\Calculator\calculatorTest.js ------
Chutzpah Error Occured:
System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
   at System.ThrowHelper.ThrowArgumentOutOfRangeException()
   at Chutzpah.TestResultsBuilder.Build(BrowserTestFileResult browserTestFileResult)
   at Chutzpah.TestRunner.RunTestsFromHtmlFile(String headlessBrowserPath, TestOptions options, TestContext testContext, List`1 testResults, ITestMethodRunnerCallback callback)
   at Chutzpah.TestRunner.RunTests(IEnumerable`1 testPaths, TestOptions options, ITestMethodRunnerCallback callback)
 While Running:C:\Users\U0120711\Documents\Visual Studio 2010\Projects\Behave\StaticContent\tests\Calculator\calculatorTest.js

========== Total Tests: 0 passed, 0 failed, 0 total ==========

Here are my tests:

Pavlov spec:

/// <reference path="../../js/External/jQuery/jquery-1.7.1.js" />
/// <reference path="../../js/External/qunit/qunit.js" />
/// <reference path="../../js/External/pavlov/pavlov.js" />
/// <reference path="../../js/Calculator/Calculator.js" />

pavlov.specify("The behavior of a calculator", function () {
    describe("Calculator", function () {
        var calculator;
        before(function () {
            calculator = new Calculator();
        });

        given([2, 0], [3, 0], [4, 0]).
            it("returns zero when multiplying by zero", function (x, y) {
                assert(0).equals(calculator.multiply(x, y));
            });

        given([2, 1], [3, 1], [4, 1]).
            it("returns the multiplicand when multiplying by one", function (x, y) {
                assert(x).equals(calculator.multiply(x, y));
            });
    });
});

QUnit test:

/// <reference path="../../js/External/jQuery/jquery-1.7.1.js" />
/// <reference path="../../js/External/qunit/qunit.js" />
/// <reference path="../../js/Calculator/Calculator.js" />

var calculator;

module("Calculator", {
    setup: function () {
        calculator = new Calculator();
    }
});

$.each([[2, 0], [3, 0], [4, 0]], function (index, pair) {
    test("given " + pair[0] + "," + pair[1] + ", returns zero when multiplying by zero", function () {
        equal(0, calculator.multiply(pair[0], pair[1]));
    });
});

$.each([[2, 1], [3, 1], [4, 1]], function (index, pair) {
    test("given " + pair[0] + "," + pair[1] + ", returns the multiplicand when multiplying by one", function () {
        equal(pair[0], calculator.multiply(pair[0], pair[1]));
    });
});

Is there something I'm doing in my tests that could be causing the VS error? Or is there a bug fix out there somewhere that I haven't found yet?

Any tips are appreciated, but please refrain from commenting on my general testing strategy, as I'm well aware of the flaws. It's only for example purposes :)


Source: (StackOverflow)

Should I test the private functions of a Javascript plugin?

I am trying to write test driven Javascript. Testing each function, I know, is crucial. But I came to a stumbling block, in that the plugin which I am writing needs to have some private functions. I cannot peek into how they are functioning. What would I need to do if I want to keep my code well tested without changing the structure of it too much? (I am ok with exposing some API, though within limits.)

I am using sinon, QUnit, and Pavlov.


Source: (StackOverflow)

Advertisements