How to call a lambda callback with mockk

You can use answers: val otm: ObjectToMock = mockk() every { otm.methodToCall(any(), any())} answers { secondArg<(String) -> Unit>().invoke(“anything”) } otm.methodToCall(“bla”){ println(“invoked with $it”) //invoked with anything } Within the answers scope you can access firstArg, secondArg etc and get it in the expected type by providing it as a generic argument. Note that I explicitly … Read more

How can I use OCMock to verify that a method is never called?

Since r69 of OCMock, it’s possible to reject a method call http://svn.mulle-kybernetik.com/OCMock/trunk/Source/Changes.txt Nice mocks / failing fast When a method is called on a mock object that has not been set up with either expect or stub the mock object will raise an exception. This fail-fast mode can be turned off by creating a “nice” … Read more

C# how to mock Configuration.GetSection(“foo:bar”).Get()

I was able to solve it using ConfigurationBuilder. Hope this will help var appSettings = @”{“”AppSettings””:{ “”Key1″” : “”Value1″”, “”Key2″” : “”Value2″”, “”Key3″” : “”Value3″” }}”; var builder = new ConfigurationBuilder(); builder.AddJsonStream(new MemoryStream(Encoding.UTF8.GetBytes(appSettings))); var configuration= builder.Build();

How to mock for testing in Haskell?

Why use unit testing when you can have Automated Specification-Based Testing? The QuickCheck library does this for you. It can generate arbitrary (mock) functions and data using the Arbitrary type-class. “Dependency Injection” is a degenerate form of implicit parameter passing. In Haskell, you can use Reader, or Free to achieve the same thing in a … Read more

Is it feasible to introduce Test Driven Development (TDD) in a mature project? [closed]

Creating a complex mocking infrastructure will probably just hide the problems in your code. I would recommend that you start with integration tests, with a test database, around the areas of the code base that you plan to change. Once you have enough tests to ensure that you won’t break anything if you make a … Read more

How to mock a dictionary in Python

How to mock a dictionary in Python is a good/direct question someone else can search, so: I suggest MagicMock instead of Mock Overload the __getitem__ from unittest.mock import MagicMock m = MagicMock() d = {‘key_1’: ‘value’} m.__getitem__.side_effect = d.__getitem__ # dict behaviour m[‘key_1’] # => ‘value’ m[‘key_2’] # => raise KeyError # mock behaviour m.foo(42) … Read more

Mocking router.events.subscribe() Angular2

I have found the answer, if someone is looking for it: import { NavigationEnd } from ‘@angular/router’; import { Observable } from ‘rxjs/Observable’; class MockRouter { public ne = new NavigationEnd(0, ‘http://localhost:4200/login’, ‘http://localhost:4200/login’); public events = new Observable(observer => { observer.next(this.ne); observer.complete(); }); } class MockRouterNoLogin { public ne = new NavigationEnd(0, ‘http://localhost:4200/dashboard’, ‘http://localhost:4200/dashboard’); public … Read more

Using @Mock and @InjectMocks

O.K, I got my mistake!!! I’ve used the @InjectMocks but initialized the same variable in the init() method… So what happened was that mockito injected the mock objects to my variable – but seconds later I ran it over – initializing that very same variable!!!

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)