如何使用PowerMockito模拟Jenkins Job的方法,该方法似乎没有从jar中导出 RunT 对象。
尝试模拟getLastUnstableBuild时遇到麻烦,因为它返回了RunT,而且由于无法访问RunT
,因此不确定如何模拟它。
我尝试使用模拟运行,Build的模拟,但似乎没有任何作用。
@RunWith(PowerMockRunner.class)
@PrepareForTest([Jenkins.class, Job.class, Run.class, Build.class, UserIdCause.class, BuildServerGlobals.class])
class BuildServerJobManagerTest {
def thisScript
def expectedJob = 'job'
def expecteBuildNumber = '1'
def expectedUser = 'user'
@Mock
private Jenkins jenkins
@Mock
private Job job
@Mock
private Run run
@Mock
private Build build
...
PowerMockito.when(jenkins.getItemByFullName(expectedJob)).thenReturn(job)
PowerMockito.when(run.getLastUnstableBuild()).thenReturn(run) //fails
PowerMockito.when(run.getLastUnstableBuild()).thenReturn(build) //fails
失败
groovy.lang.MissingMethodException:
No signature of method: hudson.model.Run$$EnhancerByMockitoWithCGLIB$$d8adb2d7
.getLastUnstableBuild() is applicable for argument types: () values: []
答案 0 :(得分:0)
通用RunT并不是问题。问题所在的方法是Job类方法而不是Run类方法
PowerMockito.when(job.getLastUnstableBuild()).thenReturn(...)