Mock objects framework

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Mock objects framework

Denis Kudriashov
I released new version of mock objects framework named Mocketry. It is renamed, cleanup and improved BehaviorMockup framework.

Short review:

Mocketry is smalltalk mock object framework based on specifications.

It support all kind specifications for object interactions:

  • arguments constraint
  • context specs
  • actions
  • usage specs
  • ordering messages.

Behavior specs build by pure message sends to mock objects and has full refactoring support.

Mock objects implements some special proxy mechanizm for support development tools (debugging).

Mocketry implements "scenario system" that allows transparent access to mock objects. If you need mock object just get it in scenario block argument:

[:mockA :mockB |
"some set up code"

[mockA someMessageWith: 20.
mockB someMessage2]
should strictly satisfy:
[mockA someMessageWith: (Kind of: Integer).
mockB someMessage2 willReturn: #someValue].

"maybe some assertions:
var should be: true.
... "
] runScenario

First block here is tested behavior. Second - expected message sends.

Or you can create MockObject instance variable in setUp method: "some := MockObject new". And you get mock object named 'some' in your "scenario tests".

Mocketry provide special SSpec-like extended DSL based on pragmas for all kind of specifications (state and behavior).

10 should be an instance of: SmallInteger
[ZeroDivide raiseSignal] should raise: ZeroDivide.
...
[mockA someMessage] should lenient satisfy: [mockA someMessage]
...

See squeaksource wiki http://www.squeaksource.com/Mocketry.html



Reply | Threaded
Open this post in threaded view
|

Re: Mock objects framework

Sophie424
"Denis Kudriashov" <[hidden email]> wrote in message

>I released new version of mock objects framework named Mocketry.

This looks really nice! Can you give some pointers on where to read a bit
more about the various kinds of specs provided (state, context, usage, ...),
and how the <pragmas> are used? (I will browse the code too :-)

Any pre-requisites? Use standard test runner?

Thanks - Sophie




Reply | Threaded
Open this post in threaded view
|

Re: Mock objects framework

Denis Kudriashov
2008/2/18, itsme213 <[hidden email]>:
"Denis Kudriashov" <[hidden email]> wrote in message

>I released new version of mock objects framework named Mocketry.

This looks really nice! Can you give some pointers on where to read a bit
more about the various kinds of specs provided (state, context, usage, ...),

I want create site about Mocketry in the next month.
Now there is only "http://www.squeaksource.com/Mocketry" wiki.
And you can browse Mocketry acceptance tests - subclasses of BehaviorSpecAcceptanceTestCase and SpecDSLAcceptanceTests.

and how the <pragmas> are used? (I will browse the code too :-)

 Spec DSL clauses is expressions like:
- 3 should be a kind of: SmallInteger
- Kind of: SmallInteger
First is used for immediately check variable for satisfying concrete spec (HierarchySpec here)
Second is used in argument constraints (for example). It will check argument for satisfying same spec (HierarchySpec).
Thus both expressions use HierarchySpec that actually know how tests object for classes relationship.
Kind class is just DSL keyword.
Kind class>>of: returns instance of concrete spec and describes "should expression" for it by pragma:

Kind class>>of: aClass
    <syntax: #(be a kind of:)>
    ^HierarchySpec for: aClass

Method can include many "syntax" pragmas ("syntax pathes").

Any pre-requisites? Use standard test runner?

Only pre-requisite is SMock package for Mocketry tests. Maybe Mocketry should have two different packages: for tests and for base code. Then base code doesn't need any pre-requisites.

About test runner:

With Mocketry use can use any Testing framework and TestRunner that you want.
You doesn't need create special Base TestCase class that provide mock objects facilities.
If you need mock object just get it from scenario block argument or testcase inst var (empty or initialized in setUp method (for example) by "instVar := MockObject new").
In test methods you don't worry about what is mock objects, you just write specification of objects interaction and test it.
Scenario system transparently creates and controls mock objects by method context.