Java Spring引导SimpleJDBCall Junit测试
我正在尝试为我的Java Spring引导SimpleJDBCall Junit测试,java,spring,spring-boot,junit,spring-test,Java,Spring,Spring Boot,Junit,Spring Test,我正在尝试为我的SimpleJdbcCall编写Junit测试,但总是在 simpleJdbcCall.withProcedureName(“MY_PROC”).declareParameters(新的SqlParameter(“ID”,Types.VARCHAR)) 在此场景中如何测试SimpleJDBCall 刀类 @Autowired JdbcTemplate jdbcTemplate; @Autowired private SimpleJdbcCall s
SimpleJdbcCall
编写Junit测试,但总是在
simpleJdbcCall.withProcedureName(“MY_PROC”).declareParameters(新的SqlParameter(“ID”,Types.VARCHAR))代码>
在此场景中如何测试SimpleJDBCall
刀类
@Autowired
JdbcTemplate jdbcTemplate;
@Autowired
private SimpleJdbcCall simpleJdbcCall;
public void call(){
//BREAKS here Exception
simpleJdbcCall.withProcedureName("MY_PROC").declareParameters(new SqlParameter("ID", Types.VARCHAR));
SqlParameterSource namedParameters = new MapSqlParameterSource("ID", "123"));
try {
result = simpleJdbcCall.execute(namedParameters);
retry();
} catch (Exception e) {
LOGGER.error("ERROR During call : " + CMAConstant.DISPOSITION_CMA + " " + e);
requestCopyOnWriteArrayList.add(modifyLeadDispositionRequest);
throw new Exception(e.getMessage());
}
}
朱尼特
JUnit的POM
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-launcher</artifactId>
<scope>test</scope>
</dependency>
org.springframework.boot
弹簧起动试验
测试
org.springframework
弹簧试验
测试
org.junit.platform
junit平台发射器
测试
不幸的是,您的代码完全错误。首先,您新创建的mockedCall
和dao
的关联性如何。Mockito不是测试dao的好地方。因为有很多机罩下的互动应该被嘲笑。我建议为dao层编写集成测试。
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-launcher</artifactId>
<scope>test</scope>
</dependency>