我试过了
@RunWith(SpringRunner.class)
@SpringBootTest
public class ExampleTest {
@Autowired
private Example example;
@Test
public void getTwoTest() {
assertEquals(new Integer(2), example.getTwo());
}
}
@TestComponent
public class Example {
public Integer getTwo(){
return 2;
}
}
我遇到的问题是this.propositionService.addProposition(this.proposition)
.subscribe(this.addSuccessCallback, this.addFailureCallback);
和addSuccessCallback
无法访问此对象。我不想使用嵌入式lambda表达式。它使代码更不干净。
答案 0 :(得分:1)
您可以bind组件的this
上下文回调,如下所示:
this.propositionService.addProposition(this.proposition)
.subscribe(this.addSuccessCallback.bind(this), this.addFailureCallback.bind(this));