Question

Eclipse Juno Service Release 1

Example of a working Unit Test ...

InRangeTest = TestCase("InRangeTest");

InRangeTest.prototype.test01 = function()
{
    var ir = new InRange(0.0, "<", Number.MAX_VALUE, "≤");
    assertTrue(ir.isInRange(0.3));
};

But, to do more than one test I believe I should be using setUp. Unless I am mistaken, the advantage of setUp is that I would not have to instantiate var ir in every unit test. So, I tried the following ...

InRangeTest = TestCase("InRangeTest");

InRangeTest.prototype.setUp = function()
{
    var ir = new InRange(0.0, "<", Number.MAX_VALUE, "≤");
};

InRangeTest.prototype.test01 = function()
{
    assertTrue(ir.isInRange(0.3));
};

Only, I get the error message

ReferenceError: ir is not defined

Replacing var ir with this.ir did not get it working.

What's wrong?

Thanks for any help in advance.

Was it helpful?

Solution

If you use this.ir in both functions it should work:

InRangeTest = TestCase("InRangeTest");

InRangeTest.prototype.setUp = function()
{
    this.ir = new InRange(0.0, "<", Number.MAX_VALUE, "≤");
};

InRangeTest.prototype.test01 = function()
{
    assertTrue(this.ir.isInRange(0.3));
};
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top