0

I have a

data class A(){ fun c(){} } .

I need to create a fake implementation of it for testing, but it says that class must be open. open modifier is incompatible with data class. Any ways to do it?

2
  • 2
    Why must you use a fake? What is the real one doing that you want changed in your tests? Commented Aug 21, 2019 at 18:03
  • In need of multiple versions of the same class? You are supposed to use an interface then. Mocking becomes easy when you write proper OOP code. Commented Aug 21, 2019 at 18:04

1 Answer 1

1

To mock final classes update mockito

testCompile 'org.mockito:mockito-core:2.8.9' and then add a folder in your resources folder called mockito-extensions that includes a text file called org.mockito.plugins.MockMaker. Inside there just add

mock-maker-inline

That should solve your problem

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.