Giter Site home page Giter Site logo

justmocklite's Introduction

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 Frameworks

  • .Net Framework 4.5+ and later.
  • .NET 5, .NET 6 preview 2
  • .Net Core 2.0 and later.

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!

justmocklite's People

Contributors

ivo-stoilov avatar lyubkanikolova avatar lyubomir-rusev avatar mbektchiev avatar mihail-vladov avatar p1ndl3sk1n avatar say25 avatar tailsu avatar tsvetko avatar tsviatko avatar vdragoev avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

justmocklite's Issues

TestFixtureSetUpAttribute and TestFixtureTearDownAttribute not found

I'm developing a TDD test with C#, .NET Framework 4.7, Nunit 3.8.0 and JustMock Lite 2017.2.821.1.

When I do:

IGenericRepository<ProductionOrder> _proOrdRepository = Mock.Create<IGenericRepository<ProductionOrder>>();

I get this message:

System.TypeInitializationException occurred
HResult=0x80131534
Message=An exception occurred in the type initializer of 'Telerik.JustMock.Core.Context.MockingContext'.
Source=Telerik.JustMock
StackTrace:
at Telerik.JustMock.Core.Context.MockingContext.get_CurrentRepository()
at Telerik.JustMock.Mock.<>c__441.b__44_0()
at Telerik.JustMock.Core.ProfilerInterceptor.GuardInternal[T](Func`1 guardedAction)
at Telerik.JustMock.Mock.CreateT
at InvesControl.Trazabilidad.TRZL.ImportBatch.Tests.LoadFinishedTrzlBatchTest.SetUpLoadFinishedTrzlBatch() in D:\MyProjects\MyProject\LoadFinishedTrzlBatchTest.cs:line 25

Inner Exception 1:
InvalidOperationException: Some attribute type among NUnit.Framework.TestFixtureSetUpAttribute, nunit.framework,NUnit.Framework.TestFixtureTearDownAttribute, nunit.framework not found.

I think that the problem is that JustMock doesn't support NUnit 3.8.0.

VisualBasic CreateLike unable to Arrange String Mock

In a Visual Basic Test Project, I've tried to use the Mock.CreateLike Methode as shown in the documentation, but I am getting an Telerik.JustMock.Core.ElevatedMockingException during Test Execution when setting up a string Property.

The following code can be used to reproduce the problem:

`
Imports Microsoft.VisualStudio.TestTools.UnitTesting
Imports Telerik.JustMock

Namespace UnitTestProject1

Public Class UnitTest1

Sub TestSub()
'this works
Mock.CreateLike(Of IToMock)(Function(x) x.Prop1 = 123)
Mock.CreateLike(Of IToMock)(Function(x) x.Prop2 = Guid.NewGuid())
'this does not
Mock.CreateLike(Of IToMock)(Function(x) x.Prop3 = "value")
End Sub
End Class

Public Interface IToMock
    Property Prop1 As Integer
    Property Prop2 As Guid
    Property Prop3 As String
End Interface

End Namespace
`

Windows 10 UWP/UAP support

Attempt #1 (does not work):
Cannot add JustMockLite to a Windows 10 Unit Test project via NuGet because UAP projects are not supported.

Attempt #2 (does not work)
Add reference to Telerik.JustMock.Portable to Windows 10 Unit Test project. This allows the project to compile and run, but any tests using Mock.Create() fail because System.Diagnostics.StackTrace.ctor is not supported.

Just a note: when Visual Studio 2015 was in RC status, we had this working. We simply added a reference to the pre-compiled Telerik.JustMocks assembly and things worked. Updating to VS RTM though broke things. Using the pre-compiled assembly results in a bunch of 'Could not find assembly System.Core v3.5.0.0' exceptions. We tried building from source and retargeting the framework to 4, 4.5, 4.5.2, and 4.6, but when we build it ourselves and try to reference the binary, VS complains that the Win10 Unit Test project is of type NetCore and the JustMock assembly targets NetFramework.

Any plans to support Windows 10 UWP/UAP projects?

Performance Issues with JustMock

I'm currently working on a PR to add JustMock to the suite of performance tests that currently exist in that repository. The problem is that some of the tests (like OneParameter and Callback) take a long time to finish for JustMock. I'm not sure why, but it's making it such that JustMock can't be added to the test suite. More to the point, the PR can't be accepted as-is because it would take too long to finish.

One thing Steve (owner of the repo) and I talked about is if the invocationCount value passed to the SimpleJobAttribute (which exists on both the MockingBenchmark and MockingBenchmark<T> classes) is reduced from 100,000 to something like 1,000, the tests then finish, but that doesn't address the underlying issue why these tests for JustMock slow down over repeated called.

There may be something in the benchmark tests with the way I've set things up with JustMock that may be incorrect. I've never used JustMock until today :). If there's something that I'm doing wrong, please let me know.

System.InvalidOperationException : Collection was modified; enumeration operation may not execute.

While executing tests in parallel a race condition is hit if two collections try to create\retire a mock of the same type at the same time. For example, one test is creating another is retiring.

System.InvalidOperationException : Collection was modified; enumeration operation may not execute.
Stack Trace:
SomeTest [FAIL]
at System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource)
at System.Collections.Generic.Dictionary2.Enumerator.MoveNext() at System.Linq.Enumerable.Any[TSource](IEnumerable1 source, Func2 predicate) at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable1 source, Func2 predicate) at Telerik.JustMock.Core.Context.HierarchicalTestFrameworkContextResolver.RepositoryOperationsWeakRef.RetireRepository(Object key, MocksRepository repo) at Telerik.JustMock.Core.Context.HierarchicalTestFrameworkContextResolver.FindRepositoryInOps(RepositoryOperationsBase entryOps, Object entryKey) at Telerik.JustMock.Core.Context.HierarchicalTestFrameworkContextResolver.ResolveRepository(UnresolvedContextBehavior unresolvedContextBehavior) at Telerik.JustMock.Core.Context.MockingContext.ResolveRepository(UnresolvedContextBehavior unresolvedContextBehavior) at Telerik.JustMock.Mock.<Create>b__86[T]() at Telerik.JustMock.Core.ProfilerInterceptor.GuardInternal[T](Func1 guardedAction)

HierarchicalTestFrameworkContextResolver.cs

AssertFailedException - JustMock xUnit method occurrence intermittently fails.

We are trying to run unit tests via xUnit and mocking method occurence using JustMockLite. Method under arrange is creating a underlying Task however, once in a while test fails with following error

build	11-May-2021 14:36:09	               Telerik.JustMock.Xunit.AssertFailedException : Multiple assertion failures:
build	11-May-2021 14:36:09	               1. Occurrence expectation failed. Expected exactly 1 call. Calls so far: 0
build	11-May-2021 14:36:09	         Arrange expression: x => x.CallAsync(IsAny(), IsAny())
build	11-May-2021 14:36:09	               2. Occurrence expectation failed. Expected exactly 1 call. Calls so far: 0
build	11-May-2021 14:36:09	         Arrange expression: x => x.NotifyAsync(IsAny())
build	11-May-2021 14:36:09	               
build	11-May-2021 14:36:09	               ---- Telerik.JustMock.Diagnostics.DebugViewDetailsException : State:
build	11-May-2021 14:36:09	         Elevated mocking: disabled
build	11-May-2021 14:36:09	         
build	11-May-2021 14:36:09	         Arrangements and expectations:
build	11-May-2021 14:36:09	                   Arrangement (id=0) x => x.Load(IsAny()):
build	11-May-2021 14:36:09	                 Met: Occurences must be in [1, 1]; calls so far: 1. 
build	11-May-2021 14:36:09	             Arrangement (id=1) x => x.InitializePolicy(IsAny(), IsAny()):
build	11-May-2021 14:36:09	                 Met: Occurences must be in [1, 1]; calls so far: 1. 
build	11-May-2021 14:36:09	             Arrangement (id=2) x => x.RequestBulkSync(IsAny(), IsAny(), IsAny()):
build	11-May-2021 14:36:09	                 Met: Occurences must be in [any, 1]; calls so far: 1. 
build	11-May-2021 14:36:09	             Arrangement (id=3) x => x.CallAsync(IsAny(), IsAny()):
build	11-May-2021 14:36:09	                 Unmet: Occurences must be in [1, 1]; calls so far: 0. 
build	11-May-2021 14:36:09	             Arrangement (id=4) x => x.NotifyAsync(IsAny()):
build	11-May-2021 14:36:09	                 Unmet: Occurences must be in [1, 1]; calls so far: 0. 
build	11-May-2021 14:36:09	         
build	11-May-2021 14:36:09	         Invocations:

Referencing nuget package from UnitTestLibrary(Windows Store) not working

Hi,
I am trying to reference the Just Mock nuget package from a Unit Test Library targeting Windows 8.1 as it is described in the How To section here.

The error I am getting is this: Could not install package 'JustMock 2016.1.107.7'. You are trying to install this package into a project that targets 'Windows,Version=v8.1', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author.

I am using Visual Studio Pro 2015.

Could you please point out what I am doing wrong?
Thanks in advance for any help

breaking change

tailsu/Telerik.JustMock.Autofac#2

Mocks.AssertAll(T instance) changed to Mocks.AssertAll(T instance, string = null)

It would be nice to keep an overload when you add an optional parameter so you don't break binary compatibility.

Unable to Run Tests in NetCoreApp2.0

Running the following in Net472 is fine, switching to NetCoreApp2.0 causes the following exception:

Test method *** threw exception: 
System.TypeInitializationException: The type initializer for 'Telerik.JustMock.SecuredReflectionMethods' threw an exception. ---> System.TypeInitializationException: The type initializer for 'Telerik.JustMock.SecuredReflection' threw an exception. ---> System.IO.FileNotFoundException: Could not load file or assembly 'System.Security.Permissions, Version=4.0.1.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified.
    at Telerik.JustMock.SecuredReflection.CheckReflectionPermission()
   at Telerik.JustMock.SecuredReflection..cctor()
--- End of inner exception stack trace ---
    at Telerik.JustMock.SecuredReflection.get_HasReflectionPermission()
   at Telerik.JustMock.SecuredReflectionMethods..cctor()
--- End of inner exception stack trace ---
    at Telerik.JustMock.Core.ExpressionUtil.EvaluateExpression(Expression expr)
   at Telerik.JustMock.Core.MocksRepository.ConvertExpressionToCallPattern(Expression expr, CallPattern callPattern)
   at Telerik.JustMock.Core.MocksRepository.Arrange[TMethodMock](Expression expr, Func`1 methodMockFactory)
   at Telerik.JustMock.Core.ProfilerInterceptor.GuardInternal[T](Func`1 guardedAction)
   at *** in ***:line 47

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.