Progress Telerik JustMock

Automocking

Easy instantiating of types with lots of dependencies or dependencies that may change over time.
Nasa, Visa, Microsoft Fox, Samsung, IBM World Bank Group, Volvo
  • Automocking Overview

    Automocking allows you to create an instance of a class without having to explicitly create each individual dependency as a unique mock. The mocked dependencies are still available to you if you need to rearrange the methods or properties as part of the test.
    Automocking is optimally suited for dealing with complex classes with multiple dependencies or classes that change over time. Tests written for these classes' members typically do not need all the dependencies explicitly mocked as they may not be used in the tested logic, but they are required for class instantiation.

    Consider the benefits of the automocking feature over creating mocks for all dependencies of a class.

    [TestMethod]
    public void ShouldMockDependenciesWithoutContainer()
    {
        // Arrange
        var firstDep = Mock.Create<IFirstDependency>();
        var secondDep = Mock.Create<ISecondDependency>();
        var thirdDep = Mock.Create<IThirdDependency>();
      
        var newInstance = new Foo(firstDep, secondDep, thirdDep);
         
        Mock.Arrange(() => secondDep.GetString()).Returns("SomeExpectedString");
         
        ....
    }
     
    [TestMethod]
    public void ShouldMockDependenciesWithoutContainer()
    {
        // Arrange
        var container = new MockingContainer<ClassUnderTest>();
         
        container.Arrange<ISecondDependency>(
           secondDep => secondDep.GetString()).Returns("SomeExpectedString");
         
        ....
    }

    Automocking documentation
Background-NextSteps

Next Steps

See Plans & Pricing

Purchase individual products or any of the bundles

Download Free Trial

With dedicated technical support.