Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/391.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 JUnit4的数据库访问延迟?_Java_Testing_Oracle Sqldeveloper_Junit4 - Fatal编程技术网

Java JUnit4的数据库访问延迟?

Java JUnit4的数据库访问延迟?,java,testing,oracle-sqldeveloper,junit4,Java,Testing,Oracle Sqldeveloper,Junit4,我正在开发一个需要JUnit版本4的Java控制台应用程序。我想做一个测试,检查用户对象中的布尔字段是否从0成功更新为1,然后再更新 public void approveTest() throws BankException { // get the test user to work on User user = udi.accessUserObject("UNITtestApprove"); // find their user i

我正在开发一个需要JUnit版本4的Java控制台应用程序。我想做一个测试,检查用户对象中的布尔字段是否从0成功更新为1,然后再更新

    public void approveTest() throws BankException {
        // get the test user to work on
        User user = udi.accessUserObject("UNITtestApprove");

        // find their user id (it is 590)
        String user_id = user.getUser_id();

        //approve the account, test that the boolean/number set to 1
        udi.approve(user_id);
        assert(user.getApproved() == 1);

        //remove approval, test that the boolean/number reset to 0
        udi.removeApproval(user_id);
        assert(user.getApproved() == 0);

    }
这个测试失败了。如果我把它分成两个测试,一个通过,另一个失败,然后反过来。我的getter似乎没有从我的数据库中获取新的、更新的值,但是在测试完成后,该值肯定会更新。当我通过访问DAO层在应用程序中使用这两种方法时,我确信这两种方法都有效


我正在使用Spring、Oracle SQL开发人员和AWS数据库。有谁能帮我发现问题,无论是订单问题还是某种时间问题?

您正在执行udi.approve(user\u id),但在检查其值之前,您没有从数据库中获取最新版本。相反,您是在断言更新之前获得的
User
对象。我想你需要更像:

  public void approveTest() throws BankException {
        // get the test user to work on
        final String userName = "UNITtestApprove";
        final User user = getUserByName(userName);

        // find their user id (it is 590)
        String userId = user.getUser_id();

        // approve the account, test that the boolean/number set to 1
        udi.approve(userId);
        assertEquals(1, getUserByName(userName).getApproved());

        // remove approval, test that the boolean/number reset to 0
        udi.removeApproval(userId);
        assertEquals(0, getUserByName(userName).getApproved());

    }

    public User getUserByName(final String userName) {
        return udi.accessUserObject(userName);
    }