質問

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