문제

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.

도움이 되었습니까?

해결책

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));
};
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top