The first step is do identify which specific non-kanji word to test with. それに - moreover, looks like a good one. I'll bring up my copy of RazorSQL and look it up. That's level 4, number 355.
Now, let's make modified copy of the first test:
public void testBlankKanjiIsHandled() {
Intent intent = new Intent(getInstrumentation().getTargetContext(),
QuestionActivity.class);
AppState appState = new AppState();
appState.jlptLevel = 4;
appState.currentQuestion = 355;
setApplication(appState);
QuestionActivity qa = startActivity(intent, null, null);
InitUtils.initializeQuestions(qa, appState);
qa.onResume();
TextView mQuestion = (TextView) qa.findViewById(R.id.display_question);
//Assert.assertEquals("青", mQuestion.getText().toString());
Assert.assertEquals(" それに", mQuestion.getText().toString());
}
And here's the result:
junit.framework.ComparisonFailure: expected:< それに> but was:<>
So, what's happening? This is actually handled in the initialize code, which reads the XML, can creates the Question object. It checks if the kanji is blank, and if so, fills it in. So, we just have to throw that logic in the data access routine.
if (null == kanji){
kanji = hiragana;
}
This might not best way to handle it, but it's not bad. An equality test will tell you if the kanji was blank, and in the meantime it will display as the question, just as if it were a regular kanji. Note this leads to a rather simple test question - one answer will exactly match the question - but the advantage is that the customer will see the word and the meaning, and hear the pronunciation.
Let's run it.
No. Maybe it's not returning a null?
if (kanji.length() == 0){
kanji = hiragana;
}
junit.framework.ComparisonFailure: expected:< ...> but was:<...>
Ouch. That weirdness again. Rerun. Same thing.
Try this:
Assert.assertEquals("xxx", mQuestion.getText().toString());
junit.framework.ComparisonFailure: expected:
Ok, go back to the original. Plus, get rid of the extra blank in the expected.
Assert.assertEquals("それに", mQuestion.getText().toString());
And all green bars. A manual test confirms that's it's working. That took no more than a few minutes. It's nice when you have the test already created.
No comments:
Post a Comment