我有这个Junit测试,其中有一个我要模拟BackendHotelService
对象的对象;我使用了@MockBean
和@Autowired
,但是在运行测试时,我都得到了java.lang.NullPointerException
@Component
public class FindHotelDataRequestTransformer extends HotelDataRequestTransformer {
public FindHotelDataRequestTransformer(BackendHotelService backendHotelService) {
super (backendHotelService);
}
..
}
和测试:
public class FindHotelDataRequestTransformerTest {
@MockBean
//@Autowired
private BackendHotelService backendHotelService;
private FindHotelDataRequestTransformer transformer;
@Before
public void setUp() {
transformer = new FindHotelDataRequestTransformer( backendHotelService);
}
从未使用过backendHotelService
答案 0 :(得分:0)
在创建新的FindHotelDataRequestTransformer时,您是否访问backendHotelService的任何字段?
如果是的话,您将需要模拟响应。
尝试以下
pdf.add_page()
pdf.set_font('Times','',10.0)
epw = pdf.w - 2*pdf.l_margin
col_width = epw/4
data = data
th = pdf.font_size
pdf.ln(4*th)
pdf.set_font('Times','B',14.0)
pdf.set_font('Times','',10.0)
#pdf.set_xy(5.5, 5.5)
pdf.ln(0.5)
for row in data:
for datum in row:
# Enter data in colums
pdf.cell(col_width, 2*th, str(datum), border=1)
pdf.ln(2*th)
#pdf.output('table.pdf','F')
#pdf.image("barchart.png", type = 'PNG')
pdf.image("barchart.png", 50, 50)
pdf.output('tuto5.pdf', 'F')