Mocking Properties

86 views
Skip to first unread message

William Madden

unread,
Apr 13, 2012, 3:49:51 AM4/13/12
to mock...@googlegroups.com
What're the limitations of mocking properties? Does mockolate create getters and setters in its bytecode for public properties that I can stub/mock or are properties just available on the mock as they would be on the real class?

For example,

class A {
  public var a : String;
}

class BTest {
  [Mock]
  public var a : A;

  public var b : B;

  [Before]
  public function beforeEach() : void {
    b = new B();
  }

  [Test]
  public function someTest() : void {
    expect(a.a = "abc"); // Would this work?
    b.someFunc();

    // Or should it be
    assertThat( a.a, equalTo('abc') );
  }
}


Drew Bourne

unread,
Apr 13, 2012, 4:44:00 AM4/13/12
to mock...@googlegroups.com
Only getters and setters are mockable, public vars are not. It is an unfortunately limitation of ABC that public variables cannot be override or proxied by public getters and setters in subclasses. 

I am undecided about whether to actively generate warnings for unmockable variables and similar situations. Your thoughts? Would it have helped diagnose your current issue?

cheers, 
Drew

William Madden

unread,
Apr 15, 2012, 7:01:43 PM4/15/12
to mock...@googlegroups.com
It's unfortunate, but I suppose it's not that bad.

I don't think warnings from the mock calls (nice(), strict() etc.) are necessary, but I think there should definitely be feedback if you try to create an unsatisfiable expectation, e.g. expect(a.a = "abc"). That would certainly have helped me.

Will
Reply all
Reply to author
Forward
0 new messages