Powerful and free mocking for .NET
Перейти к файлу
Maria Chervenkova 820b0ecf12
fix: Create tests for Mock.Reset (#220)
* fix: Create tests for Mock.Reset

* fix: SonarQube scanner findings

- Refactor test code to remove copy-paste

---------

Co-authored-by: Maria Chervenkova <maria.chervenkova@progress.com>
2024-11-19 13:20:20 +02:00
Build add aditional properties 2022-12-15 10:13:32 +02:00
Examples Support for .NET Standard 2.1 (#209) 2024-05-09 15:39:19 +03:00
SilverlightDistribution Update Silvelight DLLs with the latest release dlls 2017-06-27 14:30:24 +03:00
Solution Items initial commit 2013-12-23 10:02:11 +02:00
Telerik.JustMock fix: Set NEWOBJ_INTERCEPTION_ON_OVERWRITE var to be disabled by default (#217) 2024-11-05 15:17:34 +02:00
Telerik.JustMock.DemoLib chore: Replace tabs with spaces (#216) 2024-10-23 17:17:40 +03:00
Telerik.JustMock.DemoLibSigned chore: Replace tabs with spaces (#216) 2024-10-23 17:17:40 +03:00
Telerik.JustMock.MSTest.Tests Support for .NET Standard 2.1 (#209) 2024-05-09 15:39:19 +03:00
Telerik.JustMock.MSTest2.Tests Support for .NET Standard 2.1 (#209) 2024-05-09 15:39:19 +03:00
Telerik.JustMock.NUnit.Tests chore: Replace tabs with spaces (#216) 2024-10-23 17:17:40 +03:00
Telerik.JustMock.Portable chore: Replace tabs with spaces (#216) 2024-10-23 17:17:40 +03:00
Telerik.JustMock.Silverlight chore: Replace tabs with spaces (#216) 2024-10-23 17:17:40 +03:00
Telerik.JustMock.Silverlight.Tests chore: Replace tabs with spaces (#216) 2024-10-23 17:17:40 +03:00
Telerik.JustMock.Tests fix: Create tests for Mock.Reset (#220) 2024-11-19 13:20:20 +02:00
Telerik.JustMock.Tests.Base chore: Replace tabs with spaces (#216) 2024-10-23 17:17:40 +03:00
Telerik.JustMock.XUnit.Tests Support for .NET Standard 2.1 (#209) 2024-05-09 15:39:19 +03:00
.gitattributes initial commit 2013-12-23 10:02:11 +02:00
.gitignore Updating the ignored user specific files related to Visual Studio 2017-11-22 11:01:36 +02:00
Architecture Overview.md architecture overview 2016-01-13 16:21:46 +02:00
Build.md Add build markdown. 2018-10-08 17:57:30 +03:00
CommonAssemblyInfo.cs Changing the notice from Telerik EAD to Progress Software Corporation in JustMock Lite 2019-01-09 14:16:41 +02:00
Isolation.md add "Isolation" blog post 2016-01-07 10:38:36 +02:00
LICENSE Changing the notice Telerik AD to Telerik EAD in JustMock Lite. 2018-05-04 15:20:33 +03:00
README.md Fix .NET versions in the readme files (#218) 2024-11-06 17:43:58 +02:00
Telerik.JustMockLite.sln Add Net 5 as a target framework for test projects 2020-08-27 19:45:29 +03:00

README.md

JustMock Lite

nuget license

JustMock Lite by Telerik is for developers who practice unit testing and want to deliver exceptional software. JustMock Lite is the superior free mocking framework that makes unit testing simpler for SOLID testable projects. It is also an open source product that is easy to use, feature rich, with great power and flexibility, making it the superior choice. JustMock Lite cuts your development time and helps you create better unit tests. It enables you to perform fast and controlled tests that are independent of external dependencies like databases, web services or proprietary code. For more information, refer to our JustMock Lite website.

JustMock Lite Key Features

  • AAA pattern – JustMockLite uses the Arrange Act Assert (AAA) pattern.
  • Error-Free Mocking - Thanks to its strongly typed framework API, JustMock detects errors in your mock definitions and highlights them in Visual Studio. The JustMock Lite API fully leverages Visual Studio IntelliSense to make it easy to start mocking.
  • Mock interfaces - Allows you to test public interfaces.
  • Mock classes - Allows you to test public classes.
  • Mock properties - Allows you to test the property getter and setter.
  • Mock and rise events - Allows you to test events.
  • Control mock behavior - Allows you to control the default behavior of a mock whether be to do nothing, call the original code or throw an exception.
  • Assert call occurrences - Allows you to determine how many times a call has occurred.
  • Recursive mocking - Еnable you to mock members that are obtained as a result of "chained" calls on a mock.
  • Sequential mocking - Allows you to return different values on the same or different consecutive calls to one and the same type.
  • Support for out/ref - Mock methods accepting our and ref parameters.
  • Support for Generics - Mock generic classes and methods.
  • Fluent mocking - Allows you setup your test arrangements and expectations from your mock object.
  • Being able to seamlessly upgrade to JustMock - No rework of test is required. Simply install JustMock and make sure your project is referencing the correct assemblies.
  • And many more.

JustMock

JustMock Lite is backed by a commercial version JustMock which is more advanced mocking framework based on JustMock Lite. JustMock is for developers who doesn't want to have any restrictions and be able to mock literally everything. For more information visit our JustMock website.

JustMock Key Features

  • All key features from JustMock Lite
  • Mock non-public members and types - Allows you to mock non-public members or types.
  • Mock non-virtual methods - Allows you to mock non-virtual methods.
  • Mock extension method - Allows you to mock extension methods.
  • Mock static classes, methods, and properties - Allows you to mock static constructors, methods and properties getters and setters, set expectations and verify results.
  • Mock sealed classes - Allows you to mock sealed classes and calls to their methods/properties
  • Mock partial mocking - Allows you keep your original object and mock only the required methods.
  • Mock LINQ queries - Allows you to mock LINQ queries with custom select.
  • Mock DLL imports - Allows you to mock imported functions (decorated with the [DLLImport()] attribute)
  • Mock Ref return values and ref locals - Allows you to arrange and verify Ref return and Ref locals
  • Mock Local functions - Allows you mock Local functions.
  • Mock MsCorLib members - Allows you to mock types and methods from .NET Framework/.NET Core, i.e. from MsCorLib.
  • Mock Microsoft SharePoint - Allows you to mock types and method from SharePoint.
  • Mock Microsoft EntityFramework - Allows you to easily create in-memory mocks of the DbSet and DbContext types.
  • And many more

Examples

[TestMethod]
public void TestBookService()
{
    // Arrange - initialize objects and prepare data.
    var repository = Mock.Create<IBookRepository>();
    var expectedBook = new Book { Title = "Adventures" };
    var service = new BookService(repository);
    
    // prepare an expectation of what the GetWhere method should do when called with the specified parameters
    // and how many times the call is supposed to occur.
    Mock.Arrange(() => repository.GetWhere(book => book.Id == 1)).Returns(expectedBook).OccursOnce();

    // Act - execute the tested logic.
    Book actualBook = service.GetSingleBook(1);

    // Assert - verify that the actual result is equal to the expected.
    Assert.AreEqual(expectedBook.Title, actualBook.Title);
}

Supported .NET Frameworks

  • .NET Framework 4.7.2 and later
  • .NET LTS/STS versions via .NET Standard 2.1

Documentation

JustMock Lite and JustMock are coming with extensive Documentation and examples that will help you quickly get started with the framework.

Feedback

JustMock Lite is constantly improved through customer interaction and feedback. If you want to suggest a new feature, bug report or vote for a popular one, please visit our Feedback Portal.

Happy mocking!