background

Telerik JustMock

Automocking

  • Consider the benefits of the automocking feature over creating mocks for all dependencies of a class.
  • Part of the fastest, most flexible and complete mocking tool for crafting unit tests.
  • Our award-winning support team is available to assist you with any issues.
Mocking and Assert Functionality
  • 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
Next Steps