Created
August 6, 2010 13:46
-
-
Save ryu22e/511336 to your computer and use it in GitHub Desktop.
テストコード中でprivateなコンストラクタを呼ぶ(カバレッジを100%にするために)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* ここにテスト対象クラスの完全修飾名を入れる。 | |
*/ | |
private static String CLASS_NAME = "Sample"; | |
@Test | |
public void testSample() throws Exception { | |
try { | |
Class<?> sampleClass = Class.forName(CLASS_NAME); | |
Constructor<?>[] sample = sampleClass.getDeclaredConstructors(); | |
sample[0].setAccessible(true); | |
Object object = sample[0].newInstance(); | |
assertNotNull(object); | |
assertThat(object, instanceOf(Sample.class)); | |
} catch (Exception e) { | |
fail(e.getMessage()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
下記のimport文が必要。