2

I want to test the method-parsing and skip all the business logic. In the project I use the library Mockk.

I tried a lot of everything from the documentation, but didn’t take a look at complex implementations. The expected result was not. I used spyk<NameClass: class>, mockk<NameClass::class>(relaxed = true).

class NameClass{
    private val obj1 = obj1Init(config: Config)
    private val obj2 = obj2Init(config: Config)

    private fun obj1Init(config: Config): Obj1 = 
        Obj1(config.one, config.two)

    private fun obj2Init(config: Config): Obj2 = 
        Obj2(config.three, config.four)

    fun parseTextFile(){/*...*/}
}

class Obj1(a: Int, b: Int){ init { /*hard logic*/ } }
class Obj2(c: Int, d: Int){ init { /*hard logic*/ } }

How can I test the parseTextFile() method with minimal resources

P.s.: sry, if I poorly explained

viad899
  • 43
  • 5
  • Not sure I understand the problem exactly. Try to create `mockk` and provide `answers` that `callOriginal` implementation. Then mock private functions via `private mocking`. If this works let me know I will put this instruction to answer. – oleksiyp Sep 06 '19 at 17:51

0 Answers0