Mocking Procedure Return Values with JMockit

Mocking Procedure Return Values with JMockit

When automated testing with JUnit, you may want to hack the return value of a procedure call and intentionally make it non-zero (error). In such a case, write as follows.

You have to be careful not to write more than one @Mock in the new MockUp.

@Test
public <T extends CallableStatement> void test01 {
  new MockUp<T>(){
    @Mock
    int getInt(int i) throws SQLException {
      return -1;
    }
    @Mock
    String getString(int i) throws SQLException {
      return "error test";
    }
  };
  ~
  ~
}

コメント

Discover more from 株式会社CONFRAGE ITソリューション事業部

Subscribe now to keep reading and get access to the full archive.

Continue reading

Copied title and URL