Android Unit Test Spannablestringbuilder
Solution 1:
I don't know if it was because I did something wrong. Eventually I got it work and I'll post the solution here for your reference.
As metioned in my question, this unit test should run on an Android device or an emulator. So the first thing to do is moving it into the androidTest
directory. Only in this way will Android Studio recognize it as an instrumentation test. Also remember to update your app's gradle.build
as described here. But Android Studio (Mine is v2.1) won't allow you to run this test directly (as least I couldn't). You have to create a test suite which looks like:
package xxxxxxx.htmltestsuite;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
@RunWith(Suite.class)@Suite.SuiteClasses({
HtmlParserTest.class
})
// place holder classpublicclassHtmlTestSuite{}
Solution 2:
Today I meet a question that when I do junit test under test directory.When I create a SpannableStringBuilder,for example, SpannableStringBuilder ssb = new SpannabelStringBuilder(str), then the value of ssb is always "null". But I remove it under androidTest directory, and extends AndroidTestCase,it effect.
Post a Comment for "Android Unit Test Spannablestringbuilder"