1.marven install
jmockit website : http://jmockit.github.io/gettingStarted.html
2.code demo
CDY52177Test_021.java
package CDY52177;
import java.sql.SQLException;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.core.classloader.annotations.PowerMockIgnore;
import org.powermock.core.classloader.annotations.PrepareForTest;
import jp.co.toyota.py35401.dba.CDY52177;
import jp.co.toyota.pzd0001.CFZD0002;
import jp.co.toyota.pzd0001.CFZD0003;
import mockit.Mock;
import mockit.MockUp;
import mockit.integration.junit4.JMockit;
//@RunWith({PowerMockRunner.class})
@RunWith(JMockit.class)
@PowerMockIgnore({ "javax.management.*" })
@PrepareForTest({ System.class})
public class CDY52177Test_021 extends CDY52177_TestBase{
/**
*
* @throws SQLException
* @throws CFZD0002
* @throws CFZD0003
*/
//@Test//(expected=CFZD0002.class)
@Test(expected=ExceptionInInitializerError.class)
public void runTest227() throws SQLException, CFZD0002, CFZD0003
{
System.out.println("テストプログラム実行"+this.getTestClass());
this.commonMock1();
new MockUp<System>()
{
@Mock
public String getenv(String string) {
return "/gsms/localenv/y5env.dat";
}
};
CDY52177.y5sys_EnvSet();
//assertThat(ret, CoreMatchers.instanceOf(int.class));
}
@Override
public void setUpParameters() {
System.out.println("setUpParameters");
super.setUpParameters();
//select no data
try {
} catch (Exception e) {
// TODO 自動生成された catch ブロック
e.printStackTrace();
}
}
}
重要なcomment:
@RunWith(JMockit.class)
@PrepareForTest({ System.class})