Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Spring引导SimpleJDBCall Junit测试_Java_Spring_Spring Boot_Junit_Spring Test - Fatal编程技术网

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>