Telerik® JustMock is an easy to use mocking tool designed to help you create better unit tests, faster than ever. JustMock makes it easier for you to create mock objects and set expectations independently of external dependencies like databases, web service calls, or proprietary code.
The JustMock API is completely AAA (Arrange/Act/Assert) oriented thus helping you keep your unit tests well structured, clean and readable. No matter whether you try to mock an interface, a sealed class or a static class, the pattern you use is the same.
JustMock Lite is also available from www.nuget.org. You can use the nuget package manager console from within Visual Studio to install JustMock Lite. The command for installing JustMock Lite can be found on this page: https://nuget.org/List/Packages/JustMock.
Mocking is a concept in unit testing where real objects are substituted with fake objects that imitate the behavior of the real ones. Mocking is done so that a test can focus on the code being tested and not on the behavior or state of external dependencies.
For example, if you have a data repository class that runs business logic and then saves information to a database, you want your unit test to focus on the business logic and not on the database. Mocking the “save” calls to your database ensures your tests run quickly and do not depend on the availability or state of your database. When you’re ready to make sure the “save” calls are working, then you’re moving on to integration testing. Unit tests should not cross system boundaries, but integration tests are allowed to cross boundaries and make sure everything works together (your code, your database, your web services, etc.).
Mock objects can be created and maintained manually, but this is a time consuming and ultimately unproductive approach. A tool like Telerik JustMock allows you to focus on writing tests and forget about the mocking details. Mock objects are created automatically in memory when the tests run based on your simple configuration in the unit test. There are no “physical” mock objects that have to be maintained as your project changes.
JustMock allows you to mock everything from interfaces, virtual and abstract methods and properties to sealed classes, non-virtual methods and properties, static classes, methods and properties, even those from mscorlib like DateTime, File, FileInfo, etc. All these can be mocked without a single change of your production code.
Unlike other mocking frameworks, JustMock lets you mock:
- Sealed classes: call methods of sealed classes even with internal constructors.
- Static classes, methods, properties: create mocks of static classes, set expectations for static method and property calls, verify static method calls.
- Final methods or properties: assert final methods, overloads,
- Test objects and behaviors independently - fake any dependencies like databases, web service calls, proprietary code
- virtual and abstract methods and properties
- LINQ queries
- sealed classes
- static classes, methods, and properties
- non-virtual methods and properties
- non-public members and types
- mscorlib members
- DLL imports
- Silverlight runtime mocking
- Clean Arrange/Act/Assert syntax - keep your unit tests clean and readable
- Strongly typed fluent interface - no magic strings, compile time checks, refactoring support
- Loose mocks, Partial mocking, Recursive/nested mocking, Sequential mocking
- Hybrid mode - use profiler only when necessary (i.e. mocking final, sealed and static)
- Fast and lightweight - custom dynamic proxy library meets mocking needs only
- Support for Visual Studio - JustMock supports Visual Studio 2017, 2015, 2013, 2012 and 2010
- Support of Telerik OpenAccess, Microsoft SharePoint and Microsoft Entity Framework mocking
Support for code coverage tools, profilers, unit testing add-ins, build tools
- Integration in the TFS Code Activity Workflow - integrate JustMock in Team Foundation Server 2010, TFS 2012 or TFS 2013. Read how to integrate JustMock with TFS 2010 and TFS 2012 , or with TFS 2013 .
- MSBuild - integrate JustMock with an MSBuild build task. Read how to integrate JustMock with MSBuild .
- NAnt - integrate JustMock with an NAnt build task. Read how to integrate JustMock with NAnt .
- CruiseControl.NET - integrate JustMock along in CruiseControl.NET build. Read how to integrate JustMock with ccnet .
- Jenkins CI - integrate JustMock along in Jenkins build. Read how to integrate JustMock with Jenkins CI .
- TeamCity - integrate JustMock in TeamCity build. Read how to integrate JustMock with TeamCity .
- TestDriven.NET - Run tests, which use JustMock to mock final, static, sealed, etc members with TestDriven.NET
- NCover - JustMock supports NCover 1.3.3, 1.5.8 and 3.4.6.
- JetBrains dotTrace - JustMock supports JetBrains dotTrace version 3.1 and above.
- PostSharp - for version 126.96.36.199 and above
After the JustMock installation you can find a Getting Started Guide and example projects in the installation folder. Have a look at the example projects which provide a hands-on approach of all the features described here.
For full release notes history check this link.
The Arrange/Act/Assert pattern is a more logical and clean approach to unit testing than the legacy Record/Replay. With AAA, you group your testing actions by function, making it clear what part of your test is involved in setup versus verification. The pattern can be applied to all unit testing, but it is especially useful when mocking is involved. Record/Replay is an older pattern and it is similar to using GOTO statements in your unit tests. This makes the pattern more difficult to follow and clearly less ideal from a programming perspective. Therefore, JustMock is focused on supporting the AAA pattern. Read more about AAA in the Arrange Act Assert topic.