question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support for Answers in mock setup

See original GitHub issue

It would be very useful to be able to do a doAnswer in the same way as a doReturn or a doThrow. Something like:

private val userDao: UserDao = mock {
    on(this.save(any())) doAnswer { user ->
        UserModel(id = "userId", version = 1L, userData = user)
    }
}

At the moment I’m having to do this in an @Before or else in each test case.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:15

github_iconTop GitHub Comments

1reaction
sazzercommented, Feb 11, 2017

That’s exactly how TestNG works, and JUnit can be configured to work that way, but by default it does a new instance per test method. It’s a way to help ensure that the tests are independent of each other - barring anything external…

0reactions
nhaarmancommented, Feb 12, 2017

1.3.0 should be available on JCenter and Maven Central soon!

Read more comments on GitHub >

github_iconTop Results From Across the Web

c# - Moq: How to get to a parameter passed to a method of a ...
You can use the Mock.Callback-method: var mock = new Mock<Handler>(); SomeResponse result = null; mock.Setup(h => h.AsyncHandle(It.IsAny<SomeResponse>())) .
Read more >
How YOU can Learn Mock testing in .NET Core and C# with ...
This will teach you how to do Mock testing in .NET Core and C# with the library Moq.
Read more >
Service Mocking Overview | REST Mocking - SoapUI
The REST service mocking feature allows you to simulate a REST service by creating a mock service. You can then run it either...
Read more >
Mocking with the Postman API
Step 1: Set up a collection for mocking · Step 2: Retrieve the collection ID · Step 3: Create a mock server with...
Read more >
Stubbing and Mocking with Mockito and JUnit - Semaphore CI
Learn how to create true unit tests by mocking all external dependencies in your JUnit classes with the help of Mockito.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found