-
Notifications
You must be signed in to change notification settings - Fork 401
Unable to mock a method from the script #108
Copy link
Copy link
Closed
Milestone
Description
Hi!
Let's say I have a whatever.groovy script like this:
#!groovy
def call() {
echo 'Some steps...'
foo('bar')
}
def foo(param) {
echo param
}And what I want to do is to mock the foo method and check, whether it was called or not when call() method was called. I.e. testfile looks like this:
class WhateverTest extends BasePipelineTest {
def whatever
@Before
void setUp() {
super.setUp()
whatever = loadScript('vars/whatever.groovy')
}
@Test
void testFooCalled() throws Exception {
// here somehow mock a `foo` method...following obviously does not work:
helper.registerAllowedMethod('foo', [String.class], null)
whatever()
// here somehow check that it was called...following does not work:
assertTrue(helper.callStack.findAll { call ->
call.methodName == 'foo'
}.any { call ->
callArgsToString(call).contains('bar')
})
}
}I also tried to incorporate Mockito, but no success in this case.
Am I doing something wrong? Or is there a bug?
Thanks...I'm desperate ;)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels
Type
Fields
Give feedbackNo fields configured for issues without a type.