Telerik blogs
  • Productivity

    Future Mocking

    Mocking legacy code is hard. Especially, if it’s a third-party library and you have little control over how it’s written. It is even more difficult to unit test a type that is instantiated internally. One can argue that it should be refactored to accept dependencies via constructor injection.  However, constraints such as time, budget, experience with the offending code, or even access to the source often prevent paying down the technical debt accumulated in these legacy systems.   This post will show you how to mock an external library (concept) where it calls a login service class that cannot be sent...
    November 21, 2012
  • Productivity Testing

    Automocking with JustMock

    Auto mocking containers are designed to reduce the friction of keeping unit test beds in sync with the code being tested as systems are updated and evolve over time. Background The Dependency Inversion Principle states: High level modules should not depend upon low level modules. Both should depend upon abstractions. Abstractions should not depend upon details. Details should depend upon abstractions. As more developers follow this and the rest of Robert Martin’s SOLID principles, methods and classes become much smaller with dependent objects injected into them, typically through constructor injection. As additional dependencies are needed (or the code is refactored to improve dependency isolation), the signatures of...
    November 07, 2012
  • Productivity

    Mocking LINQ Queries

    Unit testing LINQ queries can be really challenging. This requires a deep knowledge of how LINQ queries work and how they filter results based on predicate values.  While I am adopting test first development approach, it is most likely that I want to verify the behavior of a query for correctness. In this post, I will show how easy it is to mock a LINQ query using JustMock for a given context. First, let me build up the context with a simple entity class for Employee that has two properties: Next, I created a dummy context that inherits the LINQ to SQL...
    November 02, 2012
  • Productivity

    Abstracting Dependencies with JustMock

    Unit tests are most effective when the System Under Test is isolated from its dependencies.  The best way to isolate your code (and make your code more SOLID) is through dependency injection. But even if you follow the rules of SOLID and inject all of the necessary dependencies in as interfaces, you are still faced with the fact that you depend on them. In order to test your code, something concrete has to be passed into the code in order for it to even compile.  Your production code will most likely use a factory to create concrete instances of the dependent interfaces, but that...
    October 31, 2012
  • Productivity Testing

    Getting Started with NUnit, NUnit.Should, and JustMock

    Technorati Tags: TDD,Test Driven Development,JustMock,JustCode,NUnit,NUnit.Should,Mocking Before diving into mocking with JustMock, it’s important to note that JustMock is a mocking framework, and not a testing framework.  Test frameworks allow for creating Test Fixtures, which are .NET classes decorated with the appropriate attributes so they are picked up by a Test Runner.  Test are created within a Test Fixture by writing methods (with the appropriate attributes) that exercise your code (also referred to as the System Under Test) and report the results.  Test Runners are programs that will run your tests.  There are many free testing frameworks available for .NET developers, including MSTest (included...
    October 05, 2012