Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show stacktrace of undesirable call in verify error message #19

Closed
gildor opened this issue Feb 5, 2018 · 8 comments
Closed

Show stacktrace of undesirable call in verify error message #19

gildor opened this issue Feb 5, 2018 · 8 comments

Comments

@gildor
Copy link

gildor commented Feb 5, 2018

Currently, if verify block throws an assert because you have undesired mock method call you cannot detect who called this method, so the only option to debug this case.

Currently I see something like:
java.lang.AssertionError: Verification failed: call 1 of 1: SomeClass(#10).someMethid()). 2 matching calls found, but needs at least 0 and at most 1 calls

But would be very good to have something like:

java.lang.AssertionError: Verification failed: call 1 of 1: SomeClass(#10).someMethid()). 2 matching calls found, but needs at least 0 and at most 1 calls
Call 1: SomeOtherClass:123 // Class with line number
Call 2: OneMoreClass:24
oleksiyp added a commit that referenced this issue Feb 5, 2018
@oleksiyp
Copy link
Collaborator

oleksiyp commented Feb 5, 2018

@gildor please check version 1.7.2 with applied changes and close ticket if everything is OK

@oleksiyp
Copy link
Collaborator

oleksiyp commented Feb 5, 2018

Here is exceptions from tests:


io.mockk.MockKTestSuite > MockKTestSuite.verification outcome STANDARD_OUT
    2018-02-06 00:37:09 [pool-4-thread-1] INFO  i.m.i.r.s.AnsweringStillAcceptingAnswersState - Answering 3 on MockCls(mock).otherOp(1, 2)
    2018-02-06 00:37:09 [pool-4-thread-1] INFO  io.mockk.MockKTestSuite - Exception: Verification failed: call 1 of 1: MockCls(mock).otherOp(eq(1), eq(3))). Only one matching call to MockCls(mock)/otherOp(Int, Int) happened, but arguments are not matching:
    [0]: argument: 1, matcher: eq(1), result: +
    [1]: argument: 2, matcher: eq(3), result: -

    Stack trace:
                                     io.mockk.MockCls.otherOp           (MockKTestSuite.kt:517)       
                        io.mockk.MockKTestSuite$1$5$1.invoke            (MockKTestSuite.kt:248)       
                        io.mockk.MockKTestSuite$1$5$1.invoke            (MockKTestSuite.kt:10)        
                          io.mockk.MockKTestSuite$1$4.invoke            (MockKTestSuite.kt:230)       
                          io.mockk.MockKTestSuite$1$5.invoke            (MockKTestSuite.kt:241)       
                          io.mockk.MockKTestSuite$1$5.invoke            (MockKTestSuite.kt:10)        
              io.kotlintest.Spec$runTest$callable$1$1.invoke            (Spec.kt:124)                 
              io.kotlintest.Spec$runTest$callable$1$1.invoke            (Spec.kt:15)                  
    io.kotlintest.Spec$runTest$initialInterceptor$1$1.invoke            (Spec.kt:116)                 
    io.kotlintest.Spec$runTest$initialInterceptor$1$1.invoke            (Spec.kt:15)                  
                                   io.kotlintest.Spec.interceptTestCase (Spec.kt:78)                  
      io.kotlintest.Spec$runTest$initialInterceptor$1.invoke            (Spec.kt:116)                 
      io.kotlintest.Spec$runTest$initialInterceptor$1.invoke            (Spec.kt:15)                  
                io.kotlintest.Spec$runTest$callable$1.call              (Spec.kt:124)                 
                      java.util.concurrent.FutureTask.run               (FutureTask.java:266)         
              java.util.concurrent.ThreadPoolExecutor.runWorker         (ThreadPoolExecutor.java:1142)
       java.util.concurrent.ThreadPoolExecutor$Worker.run               (ThreadPoolExecutor.java:617) 
                                     java.lang.Thread.run               (Thread.java:745)             
    2018-02-06 00:37:09 [pool-4-thread-1] INFO  i.m.i.r.s.AnsweringStillAcceptingAnswersState - Answering 3 on MockCls(mock).otherOp(1, 2)
    2018-02-06 00:37:09 [pool-4-thread-1] INFO  i.m.i.r.states.AnsweringState - Answering 3 on MockCls(mock).otherOp(1, 4)
    2018-02-06 00:37:09 [pool-4-thread-1] INFO  io.mockk.MockKTestSuite - Exception: Verification failed: call 1 of 1: MockCls(mock).otherOp(eq(1), eq(3))). No matching calls found.

    Calls to same method:
    1) MockCls(mock).otherOp(1, 2)
    2) MockCls(mock).otherOp(1, 4)

    Stack traces:
    1)                                  io.mockk.MockCls.otherOp           (MockKTestSuite.kt:517)       
                           io.mockk.MockKTestSuite$1$5$2.invoke            (MockKTestSuite.kt:256)       
                           io.mockk.MockKTestSuite$1$5$2.invoke            (MockKTestSuite.kt:10)        
                             io.mockk.MockKTestSuite$1$4.invoke            (MockKTestSuite.kt:230)       
                             io.mockk.MockKTestSuite$1$5.invoke            (MockKTestSuite.kt:253)       
                             io.mockk.MockKTestSuite$1$5.invoke            (MockKTestSuite.kt:10)        
                 io.kotlintest.Spec$runTest$callable$1$1.invoke            (Spec.kt:124)                 
                 io.kotlintest.Spec$runTest$callable$1$1.invoke            (Spec.kt:15)                  
       io.kotlintest.Spec$runTest$initialInterceptor$1$1.invoke            (Spec.kt:116)                 
       io.kotlintest.Spec$runTest$initialInterceptor$1$1.invoke            (Spec.kt:15)                  
                                      io.kotlintest.Spec.interceptTestCase (Spec.kt:78)                  
         io.kotlintest.Spec$runTest$initialInterceptor$1.invoke            (Spec.kt:116)                 
         io.kotlintest.Spec$runTest$initialInterceptor$1.invoke            (Spec.kt:15)                  
                   io.kotlintest.Spec$runTest$callable$1.call              (Spec.kt:124)                 
                         java.util.concurrent.FutureTask.run               (FutureTask.java:266)         
                 java.util.concurrent.ThreadPoolExecutor.runWorker         (ThreadPoolExecutor.java:1142)
          java.util.concurrent.ThreadPoolExecutor$Worker.run               (ThreadPoolExecutor.java:617) 
                                        java.lang.Thread.run               (Thread.java:745)             

    2)                                  io.mockk.MockCls.otherOp           (MockKTestSuite.kt:517)       
                           io.mockk.MockKTestSuite$1$5$2.invoke            (MockKTestSuite.kt:257)       
                           io.mockk.MockKTestSuite$1$5$2.invoke            (MockKTestSuite.kt:10)        
                             io.mockk.MockKTestSuite$1$4.invoke            (MockKTestSuite.kt:230)       
                             io.mockk.MockKTestSuite$1$5.invoke            (MockKTestSuite.kt:253)       
                             io.mockk.MockKTestSuite$1$5.invoke            (MockKTestSuite.kt:10)        
                 io.kotlintest.Spec$runTest$callable$1$1.invoke            (Spec.kt:124)                 
                 io.kotlintest.Spec$runTest$callable$1$1.invoke            (Spec.kt:15)                  
       io.kotlintest.Spec$runTest$initialInterceptor$1$1.invoke            (Spec.kt:116)                 
       io.kotlintest.Spec$runTest$initialInterceptor$1$1.invoke            (Spec.kt:15)                  
                                      io.kotlintest.Spec.interceptTestCase (Spec.kt:78)                  
         io.kotlintest.Spec$runTest$initialInterceptor$1.invoke            (Spec.kt:116)                 
         io.kotlintest.Spec$runTest$initialInterceptor$1.invoke            (Spec.kt:15)                  
                   io.kotlintest.Spec$runTest$callable$1.call              (Spec.kt:124)                 
                         java.util.concurrent.FutureTask.run               (FutureTask.java:266)         
                 java.util.concurrent.ThreadPoolExecutor.runWorker         (ThreadPoolExecutor.java:1142)
          java.util.concurrent.ThreadPoolExecutor$Worker.run               (ThreadPoolExecutor.java:617) 
                                        java.lang.Thread.run               (Thread.java:745)             
    2018-02-06 00:37:09 [pool-4-thread-1] INFO  i.m.i.r.s.AnsweringStillAcceptingAnswersState - Answering 3 on MockCls(mock).otherOp(1, 2)
    2018-02-06 00:37:09 [pool-4-thread-1] INFO  io.mockk.MockKTestSuite - Exception: Verification failed: call 1 of 1: MockCls(mock).manyArgsOp(eq(true), eq(false), eq(1), eq(2), eq(3), eq(4), eq(�), eq(�), eq(7), eq(8), eq(9), eq(10), eq(10.0), eq(11.0), eq(12.0), eq(13.0), eq(14), eq(15), eq(IntWrapper(data=16)), eq(IntWrapper(data=17)))) was not called.

    Calls to same mock:
    1) MockCls(mock).otherOp(1, 2)

    Stack traces:
    1)                                  io.mockk.MockCls.otherOp           (MockKTestSuite.kt:517)       
                           io.mockk.MockKTestSuite$1$5$3.invoke            (MockKTestSuite.kt:265)       
                           io.mockk.MockKTestSuite$1$5$3.invoke            (MockKTestSuite.kt:10)        
                             io.mockk.MockKTestSuite$1$4.invoke            (MockKTestSuite.kt:230)       
                             io.mockk.MockKTestSuite$1$5.invoke            (MockKTestSuite.kt:262)       
                             io.mockk.MockKTestSuite$1$5.invoke            (MockKTestSuite.kt:10)        
                 io.kotlintest.Spec$runTest$callable$1$1.invoke            (Spec.kt:124)                 
                 io.kotlintest.Spec$runTest$callable$1$1.invoke            (Spec.kt:15)                  
       io.kotlintest.Spec$runTest$initialInterceptor$1$1.invoke            (Spec.kt:116)                 
       io.kotlintest.Spec$runTest$initialInterceptor$1$1.invoke            (Spec.kt:15)                  
                                      io.kotlintest.Spec.interceptTestCase (Spec.kt:78)                  
         io.kotlintest.Spec$runTest$initialInterceptor$1.invoke            (Spec.kt:116)                 
         io.kotlintest.Spec$runTest$initialInterceptor$1.invoke            (Spec.kt:15)                  
                   io.kotlintest.Spec$runTest$callable$1.call              (Spec.kt:124)                 
                         java.util.concurrent.FutureTask.run               (FutureTask.java:266)         
                 java.util.concurrent.ThreadPoolExecutor.runWorker         (ThreadPoolExecutor.java:1142)
          java.util.concurrent.ThreadPoolExecutor$Worker.run               (ThreadPoolExecutor.java:617) 
                                        java.lang.Thread.run               (Thread.java:745)             
    2018-02-06 00:37:09 [pool-4-thread-1] INFO  io.mockk.MockKTestSuite - Exception: Verification failed: call 1 of 1: MockCls(mock).otherOp(eq(1), eq(2))) was not called
    2018-02-06 00:37:09 [pool-4-thread-1] INFO  i.m.i.r.s.AnsweringStillAcceptingAnswersState - Answering 3 on MockCls(mock).otherOp(1, 2)
    2018-02-06 00:37:09 [pool-4-thread-1] INFO  i.m.i.r.states.AnsweringState - Answering 3 on MockCls(mock).otherOp(1, 2)
    2018-02-06 00:37:09 [pool-4-thread-1] INFO  io.mockk.MockKTestSuite - Exception: Verification failed: call 1 of 1: MockCls(mock).otherOp(eq(1), eq(2))). 2 matching calls found, but needs at least 3 calls
    Calls:
    1) MockCls(mock).otherOp(1, 2)
    2) MockCls(mock).otherOp(1, 2)

    Stack traces:
    1)                                  io.mockk.MockCls.otherOp           (MockKTestSuite.kt:517)       
                           io.mockk.MockKTestSuite$1$5$5.invoke            (MockKTestSuite.kt:277)       
                           io.mockk.MockKTestSuite$1$5$5.invoke            (MockKTestSuite.kt:10)        
                             io.mockk.MockKTestSuite$1$4.invoke            (MockKTestSuite.kt:230)       
                             io.mockk.MockKTestSuite$1$5.invoke            (MockKTestSuite.kt:274)       
                             io.mockk.MockKTestSuite$1$5.invoke            (MockKTestSuite.kt:10)        
                 io.kotlintest.Spec$runTest$callable$1$1.invoke            (Spec.kt:124)                 
                 io.kotlintest.Spec$runTest$callable$1$1.invoke            (Spec.kt:15)                  
       io.kotlintest.Spec$runTest$initialInterceptor$1$1.invoke            (Spec.kt:116)                 
       io.kotlintest.Spec$runTest$initialInterceptor$1$1.invoke            (Spec.kt:15)                  
                                      io.kotlintest.Spec.interceptTestCase (Spec.kt:78)                  
         io.kotlintest.Spec$runTest$initialInterceptor$1.invoke            (Spec.kt:116)                 
         io.kotlintest.Spec$runTest$initialInterceptor$1.invoke            (Spec.kt:15)                  
                   io.kotlintest.Spec$runTest$callable$1.call              (Spec.kt:124)                 
                         java.util.concurrent.FutureTask.run               (FutureTask.java:266)         
                 java.util.concurrent.ThreadPoolExecutor.runWorker         (ThreadPoolExecutor.java:1142)
          java.util.concurrent.ThreadPoolExecutor$Worker.run               (ThreadPoolExecutor.java:617) 
                                        java.lang.Thread.run               (Thread.java:745)             

    2)                                  io.mockk.MockCls.otherOp           (MockKTestSuite.kt:517)       
                           io.mockk.MockKTestSuite$1$5$5.invoke            (MockKTestSuite.kt:278)       
                           io.mockk.MockKTestSuite$1$5$5.invoke            (MockKTestSuite.kt:10)        
                             io.mockk.MockKTestSuite$1$4.invoke            (MockKTestSuite.kt:230)       
                             io.mockk.MockKTestSuite$1$5.invoke            (MockKTestSuite.kt:274)       
                             io.mockk.MockKTestSuite$1$5.invoke            (MockKTestSuite.kt:10)        
                 io.kotlintest.Spec$runTest$callable$1$1.invoke            (Spec.kt:124)                 
                 io.kotlintest.Spec$runTest$callable$1$1.invoke            (Spec.kt:15)                  
       io.kotlintest.Spec$runTest$initialInterceptor$1$1.invoke            (Spec.kt:116)                 
       io.kotlintest.Spec$runTest$initialInterceptor$1$1.invoke            (Spec.kt:15)                  
                                      io.kotlintest.Spec.interceptTestCase (Spec.kt:78)                  
         io.kotlintest.Spec$runTest$initialInterceptor$1.invoke            (Spec.kt:116)                 
         io.kotlintest.Spec$runTest$initialInterceptor$1.invoke            (Spec.kt:15)                  
                   io.kotlintest.Spec$runTest$callable$1.call              (Spec.kt:124)                 
                         java.util.concurrent.FutureTask.run               (FutureTask.java:266)         
                 java.util.concurrent.ThreadPoolExecutor.runWorker         (ThreadPoolExecutor.java:1142)
          java.util.concurrent.ThreadPoolExecutor$Worker.run               (ThreadPoolExecutor.java:617) 
                                        java.lang.Thread.run               (Thread.java:745)             
    2018-02-06 00:37:09 [pool-4-thread-1] INFO  i.m.i.r.s.AnsweringStillAcceptingAnswersState - Answering 3 on MockCls(mock).otherOp(1, 2)
    2018-02-06 00:37:09 [pool-4-thread-1] INFO  io.mockk.MockKTestSuite - Exception: Verification failed: call 1 of 1: MockCls(mock).otherOp(eq(1), eq(2))). One matching call found, but needs at least 3 calls
    Call: MockCls(mock).otherOp(1, 2)
    Stack trace:
                                     io.mockk.MockCls.otherOp           (MockKTestSuite.kt:517)       
                        io.mockk.MockKTestSuite$1$5$6.invoke            (MockKTestSuite.kt:286)       
                        io.mockk.MockKTestSuite$1$5$6.invoke            (MockKTestSuite.kt:10)        
                          io.mockk.MockKTestSuite$1$4.invoke            (MockKTestSuite.kt:230)       
                          io.mockk.MockKTestSuite$1$5.invoke            (MockKTestSuite.kt:283)       
                          io.mockk.MockKTestSuite$1$5.invoke            (MockKTestSuite.kt:10)        
              io.kotlintest.Spec$runTest$callable$1$1.invoke            (Spec.kt:124)                 
              io.kotlintest.Spec$runTest$callable$1$1.invoke            (Spec.kt:15)                  
    io.kotlintest.Spec$runTest$initialInterceptor$1$1.invoke            (Spec.kt:116)                 
    io.kotlintest.Spec$runTest$initialInterceptor$1$1.invoke            (Spec.kt:15)                  
                                   io.kotlintest.Spec.interceptTestCase (Spec.kt:78)                  
      io.kotlintest.Spec$runTest$initialInterceptor$1.invoke            (Spec.kt:116)                 
      io.kotlintest.Spec$runTest$initialInterceptor$1.invoke            (Spec.kt:15)                  
                io.kotlintest.Spec$runTest$callable$1.call              (Spec.kt:124)                 
                      java.util.concurrent.FutureTask.run               (FutureTask.java:266)         
              java.util.concurrent.ThreadPoolExecutor.runWorker         (ThreadPoolExecutor.java:1142)
       java.util.concurrent.ThreadPoolExecutor$Worker.run               (ThreadPoolExecutor.java:617) 
                                     java.lang.Thread.run               (Thread.java:745)             
    2018-02-06 00:37:09 [pool-4-thread-1] INFO  i.m.i.r.s.AnsweringStillAcceptingAnswersState - Answering 3 on MockCls(mock).otherOp(1, 2)
    2018-02-06 00:37:09 [pool-4-thread-1] INFO  i.m.i.r.states.AnsweringState - Answering 3 on MockCls(mock).otherOp(1, 3)
    2018-02-06 00:37:09 [pool-4-thread-1] INFO  io.mockk.MockKTestSuite - Exception: Verification failed: calls are not in verification order

    Matchers: 
    MockCls(mock).otherOp(eq(1), eq(3)))
    MockCls(mock).otherOp(eq(1), eq(2)))

    Calls:
    1) MockCls(mock).otherOp(1, 2)
    2) MockCls(mock).otherOp(1, 3)

    Stack traces:
    1)                                  io.mockk.MockCls.otherOp           (MockKTestSuite.kt:517)       
                           io.mockk.MockKTestSuite$1$5$7.invoke            (MockKTestSuite.kt:293)       
                           io.mockk.MockKTestSuite$1$5$7.invoke            (MockKTestSuite.kt:10)        
                             io.mockk.MockKTestSuite$1$4.invoke            (MockKTestSuite.kt:230)       
                             io.mockk.MockKTestSuite$1$5.invoke            (MockKTestSuite.kt:290)       
                             io.mockk.MockKTestSuite$1$5.invoke            (MockKTestSuite.kt:10)        
                 io.kotlintest.Spec$runTest$callable$1$1.invoke            (Spec.kt:124)                 
                 io.kotlintest.Spec$runTest$callable$1$1.invoke            (Spec.kt:15)                  
       io.kotlintest.Spec$runTest$initialInterceptor$1$1.invoke            (Spec.kt:116)                 
       io.kotlintest.Spec$runTest$initialInterceptor$1$1.invoke            (Spec.kt:15)                  
                                      io.kotlintest.Spec.interceptTestCase (Spec.kt:78)                  
         io.kotlintest.Spec$runTest$initialInterceptor$1.invoke            (Spec.kt:116)                 
         io.kotlintest.Spec$runTest$initialInterceptor$1.invoke            (Spec.kt:15)                  
                   io.kotlintest.Spec$runTest$callable$1.call              (Spec.kt:124)                 
                         java.util.concurrent.FutureTask.run               (FutureTask.java:266)         
                 java.util.concurrent.ThreadPoolExecutor.runWorker         (ThreadPoolExecutor.java:1142)
          java.util.concurrent.ThreadPoolExecutor$Worker.run               (ThreadPoolExecutor.java:617) 
                                        java.lang.Thread.run               (Thread.java:745)             

    2)                                  io.mockk.MockCls.otherOp           (MockKTestSuite.kt:517)       
                           io.mockk.MockKTestSuite$1$5$7.invoke            (MockKTestSuite.kt:294)       
                           io.mockk.MockKTestSuite$1$5$7.invoke            (MockKTestSuite.kt:10)        
                             io.mockk.MockKTestSuite$1$4.invoke            (MockKTestSuite.kt:230)       
                             io.mockk.MockKTestSuite$1$5.invoke            (MockKTestSuite.kt:290)       
                             io.mockk.MockKTestSuite$1$5.invoke            (MockKTestSuite.kt:10)        
                 io.kotlintest.Spec$runTest$callable$1$1.invoke            (Spec.kt:124)                 
                 io.kotlintest.Spec$runTest$callable$1$1.invoke            (Spec.kt:15)                  
       io.kotlintest.Spec$runTest$initialInterceptor$1$1.invoke            (Spec.kt:116)                 
       io.kotlintest.Spec$runTest$initialInterceptor$1$1.invoke            (Spec.kt:15)                  
                                      io.kotlintest.Spec.interceptTestCase (Spec.kt:78)                  
         io.kotlintest.Spec$runTest$initialInterceptor$1.invoke            (Spec.kt:116)                 
         io.kotlintest.Spec$runTest$initialInterceptor$1.invoke            (Spec.kt:15)                  
                   io.kotlintest.Spec$runTest$callable$1.call              (Spec.kt:124)                 
                         java.util.concurrent.FutureTask.run               (FutureTask.java:266)         
                 java.util.concurrent.ThreadPoolExecutor.runWorker         (ThreadPoolExecutor.java:1142)
          java.util.concurrent.ThreadPoolExecutor$Worker.run               (ThreadPoolExecutor.java:617) 
                                        java.lang.Thread.run               (Thread.java:745)             
    2018-02-06 00:37:10 [pool-4-thread-1] INFO  i.m.i.r.s.AnsweringStillAcceptingAnswersState - Answering 3 on MockCls(mock).otherOp(1, 3)
    2018-02-06 00:37:10 [pool-4-thread-1] INFO  io.mockk.MockKTestSuite - Exception: Verification failed: less calls happened then demanded by order verification sequence. 

    Matchers: 
    MockCls(mock).otherOp(eq(1), eq(3)))
    MockCls(mock).otherOp(eq(1), eq(2)))

    Calls:
    1) MockCls(mock).otherOp(1, 3)

    Stack traces:
    1)                                  io.mockk.MockCls.otherOp           (MockKTestSuite.kt:517)       
                           io.mockk.MockKTestSuite$1$5$8.invoke            (MockKTestSuite.kt:304)       
                           io.mockk.MockKTestSuite$1$5$8.invoke            (MockKTestSuite.kt:10)        
                             io.mockk.MockKTestSuite$1$4.invoke            (MockKTestSuite.kt:230)       
                             io.mockk.MockKTestSuite$1$5.invoke            (MockKTestSuite.kt:301)       
                             io.mockk.MockKTestSuite$1$5.invoke            (MockKTestSuite.kt:10)        
                 io.kotlintest.Spec$runTest$callable$1$1.invoke            (Spec.kt:124)                 
                 io.kotlintest.Spec$runTest$callable$1$1.invoke            (Spec.kt:15)                  
       io.kotlintest.Spec$runTest$initialInterceptor$1$1.invoke            (Spec.kt:116)                 
       io.kotlintest.Spec$runTest$initialInterceptor$1$1.invoke            (Spec.kt:15)                  
                                      io.kotlintest.Spec.interceptTestCase (Spec.kt:78)                  
         io.kotlintest.Spec$runTest$initialInterceptor$1.invoke            (Spec.kt:116)                 
         io.kotlintest.Spec$runTest$initialInterceptor$1.invoke            (Spec.kt:15)                  
                   io.kotlintest.Spec$runTest$callable$1.call              (Spec.kt:124)                 
                         java.util.concurrent.FutureTask.run               (FutureTask.java:266)         
                 java.util.concurrent.ThreadPoolExecutor.runWorker         (ThreadPoolExecutor.java:1142)
          java.util.concurrent.ThreadPoolExecutor$Worker.run               (ThreadPoolExecutor.java:617) 
                                        java.lang.Thread.run               (Thread.java:745)             
    2018-02-06 00:37:10 [pool-4-thread-1] INFO  i.m.i.r.s.AnsweringStillAcceptingAnswersState - Answering 3 on MockCls(mock).otherOp(1, 3)
    2018-02-06 00:37:10 [pool-4-thread-1] INFO  io.mockk.MockKTestSuite - Exception: Verification failed: number of calls happened not matching exact number of verification sequence

    Matchers: 
    MockCls(mock).otherOp(eq(1), eq(3)))
    MockCls(mock).otherOp(eq(1), eq(2)))

    Calls:
    1) MockCls(mock).otherOp(1, 3)

    Stack traces:
    1)                                  io.mockk.MockCls.otherOp           (MockKTestSuite.kt:517)       
                           io.mockk.MockKTestSuite$1$5$9.invoke            (MockKTestSuite.kt:314)       
                           io.mockk.MockKTestSuite$1$5$9.invoke            (MockKTestSuite.kt:10)        
                             io.mockk.MockKTestSuite$1$4.invoke            (MockKTestSuite.kt:230)       
                             io.mockk.MockKTestSuite$1$5.invoke            (MockKTestSuite.kt:311)       
                             io.mockk.MockKTestSuite$1$5.invoke            (MockKTestSuite.kt:10)        
                 io.kotlintest.Spec$runTest$callable$1$1.invoke            (Spec.kt:124)                 
                 io.kotlintest.Spec$runTest$callable$1$1.invoke            (Spec.kt:15)                  
       io.kotlintest.Spec$runTest$initialInterceptor$1$1.invoke            (Spec.kt:116)                 
       io.kotlintest.Spec$runTest$initialInterceptor$1$1.invoke            (Spec.kt:15)                  
                                      io.kotlintest.Spec.interceptTestCase (Spec.kt:78)                  
         io.kotlintest.Spec$runTest$initialInterceptor$1.invoke            (Spec.kt:116)                 
         io.kotlintest.Spec$runTest$initialInterceptor$1.invoke            (Spec.kt:15)                  
                   io.kotlintest.Spec$runTest$callable$1.call              (Spec.kt:124)                 
                         java.util.concurrent.FutureTask.run               (FutureTask.java:266)         
                 java.util.concurrent.ThreadPoolExecutor.runWorker         (ThreadPoolExecutor.java:1142)
          java.util.concurrent.ThreadPoolExecutor$Worker.run               (ThreadPoolExecutor.java:617) 
                                        java.lang.Thread.run               (Thread.java:745)             
    2018-02-06 00:37:10 [pool-4-thread-1] INFO  i.m.i.r.s.AnsweringStillAcceptingAnswersState - Answering 3 on MockCls(mock).otherOp(1, 2)
    2018-02-06 00:37:10 [pool-4-thread-1] INFO  i.m.i.r.states.AnsweringState - Answering 3 on MockCls(mock).otherOp(1, 3)
    2018-02-06 00:37:10 [pool-4-thread-1] INFO  io.mockk.MockKTestSuite - Exception: Verification failed: calls are not exactly matching verification sequence

    Matchers: 
    MockCls(mock).otherOp(eq(1), eq(3)))
    MockCls(mock).otherOp(eq(1), eq(2)))

    Calls:
    1) MockCls(mock).otherOp(1, 2)
    2) MockCls(mock).otherOp(1, 3)

    Stack traces:
    1)                                  io.mockk.MockCls.otherOp           (MockKTestSuite.kt:517)       
                          io.mockk.MockKTestSuite$1$5$10.invoke            (MockKTestSuite.kt:324)       
                          io.mockk.MockKTestSuite$1$5$10.invoke            (MockKTestSuite.kt:10)        
                             io.mockk.MockKTestSuite$1$4.invoke            (MockKTestSuite.kt:230)       
                             io.mockk.MockKTestSuite$1$5.invoke            (MockKTestSuite.kt:321)       
                             io.mockk.MockKTestSuite$1$5.invoke            (MockKTestSuite.kt:10)        
                 io.kotlintest.Spec$runTest$callable$1$1.invoke            (Spec.kt:124)                 
                 io.kotlintest.Spec$runTest$callable$1$1.invoke            (Spec.kt:15)                  
       io.kotlintest.Spec$runTest$initialInterceptor$1$1.invoke            (Spec.kt:116)                 
       io.kotlintest.Spec$runTest$initialInterceptor$1$1.invoke            (Spec.kt:15)                  
                                      io.kotlintest.Spec.interceptTestCase (Spec.kt:78)                  
         io.kotlintest.Spec$runTest$initialInterceptor$1.invoke            (Spec.kt:116)                 
         io.kotlintest.Spec$runTest$initialInterceptor$1.invoke            (Spec.kt:15)                  
                   io.kotlintest.Spec$runTest$callable$1.call              (Spec.kt:124)                 
                         java.util.concurrent.FutureTask.run               (FutureTask.java:266)         
                 java.util.concurrent.ThreadPoolExecutor.runWorker         (ThreadPoolExecutor.java:1142)
          java.util.concurrent.ThreadPoolExecutor$Worker.run               (ThreadPoolExecutor.java:617) 
                                        java.lang.Thread.run               (Thread.java:745)             

    2)                                  io.mockk.MockCls.otherOp           (MockKTestSuite.kt:517)       
                          io.mockk.MockKTestSuite$1$5$10.invoke            (MockKTestSuite.kt:325)       
                          io.mockk.MockKTestSuite$1$5$10.invoke            (MockKTestSuite.kt:10)        
                             io.mockk.MockKTestSuite$1$4.invoke            (MockKTestSuite.kt:230)       
                             io.mockk.MockKTestSuite$1$5.invoke            (MockKTestSuite.kt:321)       
                             io.mockk.MockKTestSuite$1$5.invoke            (MockKTestSuite.kt:10)        
                 io.kotlintest.Spec$runTest$callable$1$1.invoke            (Spec.kt:124)                 
                 io.kotlintest.Spec$runTest$callable$1$1.invoke            (Spec.kt:15)                  
       io.kotlintest.Spec$runTest$initialInterceptor$1$1.invoke            (Spec.kt:116)                 
       io.kotlintest.Spec$runTest$initialInterceptor$1$1.invoke            (Spec.kt:15)                  
                                      io.kotlintest.Spec.interceptTestCase (Spec.kt:78)                  
         io.kotlintest.Spec$runTest$initialInterceptor$1.invoke            (Spec.kt:116)                 
         io.kotlintest.Spec$runTest$initialInterceptor$1.invoke            (Spec.kt:15)                  
                   io.kotlintest.Spec$runTest$callable$1.call              (Spec.kt:124)                 
                         java.util.concurrent.FutureTask.run               (FutureTask.java:266)         
                 java.util.concurrent.ThreadPoolExecutor.runWorker         (ThreadPoolExecutor.java:1142)
          java.util.concurrent.ThreadPoolExecutor$Worker.run               (ThreadPoolExecutor.java:617) 
                                        java.lang.Thread.run               (Thread.java:745)             
    2018-02-06 00:37:10 [pool-4-thread-1] INFO  i.m.i.r.s.AnsweringStillAcceptingAnswersState - Answering 3 on MockCls(mock).otherOp(1, 2)
    2018-02-06 00:37:10 [pool-4-thread-1] INFO  i.m.i.r.states.AnsweringState - Answering 3 on MockCls(mock).otherOp(1, 3)
    2018-02-06 00:37:10 [pool-4-thread-1] INFO  io.mockk.MockKTestSuite - Exception: Verification failed: some calls were not matched: [MockCls(mock).otherOp(1, 3)]

    Matchers: 
    MockCls(mock).otherOp(eq(1), eq(2)))

    Calls:
    1) MockCls(mock).otherOp(1, 2)
    2) MockCls(mock).otherOp(1, 3)

    Stack traces:
    1)                                  io.mockk.MockCls.otherOp           (MockKTestSuite.kt:517)       
                          io.mockk.MockKTestSuite$1$5$11.invoke            (MockKTestSuite.kt:335)       
                          io.mockk.MockKTestSuite$1$5$11.invoke            (MockKTestSuite.kt:10)        
                             io.mockk.MockKTestSuite$1$4.invoke            (MockKTestSuite.kt:230)       
                             io.mockk.MockKTestSuite$1$5.invoke            (MockKTestSuite.kt:332)       
                             io.mockk.MockKTestSuite$1$5.invoke            (MockKTestSuite.kt:10)        
                 io.kotlintest.Spec$runTest$callable$1$1.invoke            (Spec.kt:124)                 
                 io.kotlintest.Spec$runTest$callable$1$1.invoke            (Spec.kt:15)                  
       io.kotlintest.Spec$runTest$initialInterceptor$1$1.invoke            (Spec.kt:116)                 
       io.kotlintest.Spec$runTest$initialInterceptor$1$1.invoke            (Spec.kt:15)                  
                                      io.kotlintest.Spec.interceptTestCase (Spec.kt:78)                  
         io.kotlintest.Spec$runTest$initialInterceptor$1.invoke            (Spec.kt:116)                 
         io.kotlintest.Spec$runTest$initialInterceptor$1.invoke            (Spec.kt:15)                  
                   io.kotlintest.Spec$runTest$callable$1.call              (Spec.kt:124)                 
                         java.util.concurrent.FutureTask.run               (FutureTask.java:266)         
                 java.util.concurrent.ThreadPoolExecutor.runWorker         (ThreadPoolExecutor.java:1142)
          java.util.concurrent.ThreadPoolExecutor$Worker.run               (ThreadPoolExecutor.java:617) 
                                        java.lang.Thread.run               (Thread.java:745)             

    2)                                  io.mockk.MockCls.otherOp           (MockKTestSuite.kt:517)       
                          io.mockk.MockKTestSuite$1$5$11.invoke            (MockKTestSuite.kt:336)       
                          io.mockk.MockKTestSuite$1$5$11.invoke            (MockKTestSuite.kt:10)        
                             io.mockk.MockKTestSuite$1$4.invoke            (MockKTestSuite.kt:230)       
                             io.mockk.MockKTestSuite$1$5.invoke            (MockKTestSuite.kt:332)       
                             io.mockk.MockKTestSuite$1$5.invoke            (MockKTestSuite.kt:10)        
                 io.kotlintest.Spec$runTest$callable$1$1.invoke            (Spec.kt:124)                 
                 io.kotlintest.Spec$runTest$callable$1$1.invoke            (Spec.kt:15)                  
       io.kotlintest.Spec$runTest$initialInterceptor$1$1.invoke            (Spec.kt:116)                 
       io.kotlintest.Spec$runTest$initialInterceptor$1$1.invoke            (Spec.kt:15)                  
                                      io.kotlintest.Spec.interceptTestCase (Spec.kt:78)                  
         io.kotlintest.Spec$runTest$initialInterceptor$1.invoke            (Spec.kt:116)                 
         io.kotlintest.Spec$runTest$initialInterceptor$1.invoke            (Spec.kt:15)                  
                   io.kotlintest.Spec$runTest$callable$1.call              (Spec.kt:124)                 
                         java.util.concurrent.FutureTask.run               (FutureTask.java:266)         
                 java.util.concurrent.ThreadPoolExecutor.runWorker         (ThreadPoolExecutor.java:1142)
          java.util.concurrent.ThreadPoolExecutor$Worker.run               (ThreadPoolExecutor.java:617) 
                                        java.lang.Thread.run               (Thread.java:745)             

@gildor
Copy link
Author

gildor commented Feb 7, 2018

Thank you. Can confirm that now I can solve such cases without debugging, stack traces are very informative

The only enhancement that I see to remove mockk internal calls from stacktrace.
For example, this is part of stack trace:

                         io.mockk.impl.InternalPlatform.captureStackTrace        (InternalPlatform.kt:116)                  
                                                            io.mockk.impl.stub.MockKStub.handleInvocation         (MockKStub.kt:160)                         
                          io.mockk.impl.instantiation.JvmMockFactoryHelper$mockHandler$1.invoke                   (JvmMockFactoryHelper.kt:17)               
                          io.mockk.impl.instantiation.JvmMockFactoryHelper$mockHandler$1.invoke                   (JvmMockFactoryHelper.kt:13)               
        io.mockk.impl.instantiation.JvmMockFactoryKt$sam$MockKInvocationHandler$4dff1f07.invocation               (JvmMockFactory.kt:-1)                     
                                                    io.mockk.proxy.MockKProxyInterceptor.intercept                (MockKProxyInterceptor.java:20)            
  com.bandlab.soundbanks.manager.SoundBanksService$ByteBuddy$TzvhGVBh$ByteBuddy$ETvUaZyT.soundbanks               (-:-1)                                     
                                 com.bandlab.soundbanks.manager.impl.CachedSoundBanksApi.<init>                   (CachedSoundBanksApi.kt:21)                
                 com.bandlab.soundbanks.manager.impl.CachedSoundBanksApiTest$cachedApi$2.invoke                   (CachedSoundBanksApiTest.kt:182)           
                 com.bandlab.soundbanks.manager.impl.CachedSoundBanksApiTest$cachedApi$2.invoke                   (CachedSoundBanksApiTest.kt:25)            
                                                             kotlin.SynchronizedLazyImpl.getValue                 (Lazy.kt:131) 

CachedSoundBanksApi.<init> is correct place, but you also can see methods generated by byte buddy and mockk internals. It would be nice to modify stacktract to remove those methods from stack trace. But not that there is an easy way to detect point where is boundary between client code and library code

Anyway, issue solved. I can log this stacktrace enhancement proposal to a separate issue.

@oleksiyp
Copy link
Collaborator

oleksiyp commented Feb 7, 2018

MockKProxyInterceptor.intercept is good point to cut. As ByteBuddy class is actually subclass of client code i.e. it would show soundbanks on the top. I actually implemented such stack cut but for final class mocks. Forgot about this ByteBuddy subclassing.

@gildor
Copy link
Author

gildor commented Feb 9, 2018

@oleksiyp Yeah sounds great. ByteBuddy subclass would be nice to cut too, it doesn't have line number information. Should I move this to a separate issue or keep this task open for now?

@oleksiyp
Copy link
Collaborator

oleksiyp commented Feb 9, 2018

Just keep it open. I'll release it with some other fixes and close

@oleksiyp
Copy link
Collaborator

oleksiyp commented Feb 9, 2018

@gildor check if version 1.7.3 fix your request. if everything ok please close the ticket. thank you

@gildor
Copy link
Author

gildor commented Feb 12, 2018

@oleksiyp Yes, this works perfectly. And the even ByteBuddy call is looking nice now.
Thanks for your work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants