CodeCoverage по сравнению с ExpectedException

Я нашел, что звук очень непоследователен в средстве моделирования (2,1 SDK). Иногда это работает, иногда это не делает. Даже когда это действительно работает, это обычно очень изменчиво и искажено (при игре звуковых файлов, таких как mp3).

Несколько вещей помнить:

  • вызов AudioSessionInitialize, как только Ваше приложение заканчивает запускаться
  • , установил kAudioSessionProperty_AudioCategory свойство для сессии через AudioSessionSetProperty (со значением такой как kAudioSessionCategory_MediaPlayback)
  • вызов AudioSessionSetActive(YES)

, Конечно, когда все остальное перестало работать, просто выполните его на своих аппаратных средствах!

РЕДАКТИРОВАНИЕ: Теперь, когда 2,2 SDK были выпущены, у меня не было проблем со звуком в средстве моделирования. Они, должно быть, исправили ошибки! Я настоятельно рекомендую, чтобы Вы обновили до 2,2 SDK.

8
задан mafu 22 October 2009 в 11:58
поделиться

2 ответа

What you are suggesting is valid. Aside from you code coverage issue, I would argue it is better than using the ExpectedException attribute as it explicitly shows which line of the test is expected to throw the exception. Using ExpectedException means that any line of code in the test can throw the expected exception type and the test will still pass. If the error originates from another call that was not expected to throw, it can disguise the fact that the test should be failing because the line that should be throwing isn't.

What would be a useful modification to what you have proposed would be to return the caught exception:

public static _T ExpectException<_T> (Action action) where _T: Exception
{
    try { action(); }
    catch (_T ex) { return ex; }
    Assert.Fail ("Expected " + typeof(_T));
    return null;
}

This would enable the test code to further assert the exception if it desired (ie. to check a particular message was used).

NUnit (though it doesn't look like you are using it as you have a TestMethod attribute) has a built-in construct similar to what you have proposed:

Assert.Throws<ArgumentNullException>(() => Foo.DoStuff(null))
10
ответ дан 5 December 2019 в 11:25
поделиться

Да, это довольно стандартная плата - многие наши тесты делают то же самое. В то же время вы должны задаться вопросом, не придаете ли вы слишком большое значение покрытию кода, если эти половинчатые ответвления так много весят, что стоит затраченных усилий.

0
ответ дан 5 December 2019 в 11:25
поделиться
Другие вопросы по тегам:

Похожие вопросы: