テストのときは別の初期化をしたいときどうしたらいいんだろうと悩んでたら方法を見つけたのでメモ。
答えはここにあった
| I need to determine in runtime from code if the application is run under TestInstrumentation.I could initialize the test environment with some env/system variable, but Eclipse ADK launch configur... How to determine if Android Application is started with JUnit testing instrum... - Stack Overflow |
private static boolean isTestMode() {
boolean result;
try {
application.getClassLoader().loadClass("foo.bar.test.SomeTest");
// alternatively (see the comment below):
// Class.forName("foo.bar.test.SomeTest");
result = true;
} catch (final Exception e) {
result = false;
}
return result;
} テストのクラスがあるかチェックしてその判定をもってテスト可動化するsTestModeというメソッドを作って判定するらしい。
なんかやりかたがすげースマートじゃないけどできたからまぁいっか。
でもiOSもこんな感じだし発想的には似たようなもんかな。
if (NSClassFromString(@"XCTestCase")) {
return;
}
こんにちは。virapture…
View Comments
I don't think the title of your article matches the content lol. Just kidding, mainly because I had some doubts after reading the article.
I don't think the title of your article matches the content lol. Just kidding, mainly because I had some doubts after reading the article.
I don't think the title of your article matches the content lol. Just kidding, mainly because I had some doubts after reading the article.
Your point of view caught my eye and was very interesting. Thanks. I have a question for you. https://www.binance.info/ru/register-person?ref=V3MG69RO