Intereting Posts

Тест Simpe Android JUnit висит в Eclipse

Я читал книгу об Android-тестировании и реализовал этот пример:

public class TemperatureConverterActivityTests extends ActivityInstrumentationTestCase2<TemperatureConverterActivity> { private TemperatureConverterActivity mActivity; private EditText mCelsius; private EditText mFarenheit; public TemperatureConverterActivityTests() { this("TemperatureConverterActivityTests"); } public TemperatureConverterActivityTests(String name) { super(TemperatureConverterActivity.class); setName(name); } protected void setUp() throws Exception { super.setUp(); mActivity = getActivity(); mCelsius = (EditText) mActivity .findViewById(org.mighter.tc.R.id.celsius); mFarenheit = (EditText) mActivity .findViewById(org.mighter.tc.R.id.farenheit); } protected void tearDown() throws Exception { } public final void testPreconditions() { assertNotNull(mActivity); } public final void testHasInputFields() { assertNotNull(mCelsius); assertNotNull(mFarenheit); } } 

Однако тест не заканчивается.

Что я получаю в консоли:

 Android Launch! adb is running normally. Performing android.test.InstrumentationTestRunner JUnit launch Automatic Target Mode: Several compatible targets. Please select a target device. Uploading TemperatureConverterTest.apk onto device '80A358103041548074' Installing TemperatureConverterTest.apk... Success! Project dependency found, installing: TemperatureConverter Application already deployed. No need to reinstall. Launching instrumentation android.test.InstrumentationTestRunner on device 80A358103041548074 Collecting test information Test run failed: Instrumentation run failed due to 'Process crashed.' Test run finished Sending test information to Eclipse Running tests... 

И тогда это зависает, вот JUnit:

Введите описание изображения здесь

Единственная информация из LogCat:

 05-28 17:23:54.952: W/ActivityManager(224): Crash of app org.mighter.tc running instrumentation ComponentInfo{org.mighter.tc.test/android.test.InstrumentationTestRunner} 05-28 17:23:55.042: I/TestRunner(7174): <!>android.test.TestPrinter 50<!> started: testHasInputFields(org.mighter.tc.test.TemperatureConverterActivityTests) 05-28 17:23:55.062: I/TestRunner(7174): <!>android.test.TestPrinter 56<!> finished: testHasInputFields(org.mighter.tc.test.TemperatureConverterActivityTests) 05-28 17:23:55.062: I/TestRunner(7174): <!>android.test.TestPrinter 77<!> passed: testHasInputFields(org.mighter.tc.test.TemperatureConverterActivityTests) 05-28 17:23:55.072: I/TestRunner(7174): <!>android.test.TestPrinter 50<!> started: testPreconditions(org.mighter.tc.test.TemperatureConverterActivityTests) 05-28 17:23:55.082: I/TestRunner(7174): <!>android.test.TestPrinter 56<!> finished: testPreconditions(org.mighter.tc.test.TemperatureConverterActivityTests) 05-28 17:23:55.082: I/TestRunner(7174): <!>android.test.TestPrinter 77<!> passed: testPreconditions(org.mighter.tc.test.TemperatureConverterActivityTests) 05-28 17:23:55.652: I/TestRunner(7194): <!>android.test.TestPrinter 50<!> started: testHasInputFields(org.mighter.tc.test.TemperatureConverterActivityTests) 05-28 17:23:55.853: I/TestRunner(7194): <!>android.test.TestPrinter 56<!> finished: testHasInputFields(org.mighter.tc.test.TemperatureConverterActivityTests) 05-28 17:23:55.853: I/TestRunner(7194): <!>android.test.TestPrinter 77<!> passed: testHasInputFields(org.mighter.tc.test.TemperatureConverterActivityTests) 05-28 17:23:55.853: I/TestRunner(7194): <!>android.test.TestPrinter 50<!> started: testPreconditions(org.mighter.tc.test.TemperatureConverterActivityTests) 

Пробовал отлаживать, но он никогда не достигает testPreconditions (). Благодарю.

Просто нужно было вызвать super в tearDown ();