- 配置
build.gradle
依賴
dependencies {
androidTestImplementation ‘a(chǎn)ndroidx.test??1.4.0’
androidTestImplementation ‘a(chǎn)ndroidx.test:rules:1.4.0’
}
android {
defaultConfig {
testInstrumentationRunner “androidx.test.runner.AndroidJUnitRunner”
}
}
測試樣例
測試代碼
本例子參考google
官方網(wǎng)站。因為官網(wǎng)里面很多類沒有給到,所以進行了一波補充完善。????????點擊可前往官網(wǎng)。
以下示例顯示了如何編寫儀器單元測試來驗證 Parcelable
接口是否被 LogHistory
類正確實現(xiàn):???♀?
import android.os.Parcel
import android.os.Parcelable
import android.os.Parcelable.Creator
import androidx.test.runner.AndroidJUnit4
import org.junit.Assert
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
const val TEST_STRING = “This is a string”
const val TEST_LONG = 12345678L
// @RunWith is required only if you use a mix of JUnit3 and JUnit4.
@RunWith(AndroidJUnit4::class)
class LogHistoryAndroidUnitTest {
private lateinit var logHistory: LogHistory
@Before
fun createLogHistory() {
logHistory = LogHistory(TEST_STRING, TEST_LONG)
}
@Test
fun logHistory_ParcelableWriteRead() {
val parcel = Parcel.obtain()
logHistory.apply {
// 寫數(shù)據(jù)
writeToParcel(parcel, describeContents())
}
// 完成寫入后,置包裹以進行讀取。
parcel.setDataPosition(0)
// 讀取數(shù)據(jù)
val createdFromParcel: LogHistory = LogHistory.CREATOR.createFromParcel(parcel)
// 驗證數(shù)據(jù)的正確性
Assert.assertTrue(“error TEST_STRING”, createdFromParcel.strValue == TEST_STRING)
Assert.assertTrue(“error TEST_LONG”, createdFromParcel.longValue == TEST_LONG)
}
}
class LogHistory(val strValue: String = “”, val longValue: Long = 0L) : Parcelable {
constructor(source: Parcel) : this(source.readString() ?: “”, source.readLong())
自我介紹一下,小編13年上海交大畢業(yè),曾經(jīng)在小公司待過,也去過華為、OPPO等大廠,18年進入阿里一直到現(xiàn)在。
深知大多數(shù)Android工程師,想要提升技能,往往是自己摸索成長或者是報班學習,但對于培訓機構(gòu)動則幾千的學費,著實壓力不小。自己不成體系的自學效果低效又漫長,而且極易碰到天花板技術(shù)停滯不前!
因此收集整理了一份《2024年Android移動開發(fā)全套學習資料》,初衷也很簡單,就是希望能夠幫助到想自學提升又不知道該從何學起的朋友,同時減輕大家的負擔。
既有適合小白學習的零基礎資料,也有適合3年以上經(jīng)驗的小伙伴深入學習提升的進階課程,基本涵蓋了95%以上Android開發(fā)知識點,真正體系化!
由于文件比較大,這里只是將部分目錄大綱截圖出來,每個節(jié)點里面都包含大廠面經(jīng)、學習筆記、源碼講義、實戰(zhàn)項目、講解視頻,并且后續(xù)會持續(xù)更新
如果你覺得這些內(nèi)容對你有幫助,可以添加V獲取:vip204888 (備注Android)
最后
文章所有資料全部已經(jīng)打包整理好,另外小編手頭上整理了大量Android架構(gòu)師全套學習資料,Android核心高級技術(shù)PDF文檔+全套高級學習資料+視頻+2021 BAT 大廠面試真題解析
資料展示:
本文已被CODING開源項目:《Android學習筆記總結(jié)+移動架構(gòu)視頻+大廠面試真題+項目實戰(zhàn)源碼》收錄
一個人可以走的很快,但一群人才能走的更遠。如果你從事以下工作或?qū)σ韵赂信d趣,歡迎戳這里加入程序員的圈子,讓我們一起學習成長!
AI人工智能、Android移動開發(fā)、AIGC大模型、C C#、Go語言、Java、Linux運維、云計算、MySQL、PMP、網(wǎng)絡安全、Python爬蟲、UE5、UI設計、Unity3D、Web前端開發(fā)、產(chǎn)品經(jīng)理、車載開發(fā)、大數(shù)據(jù)、鴻蒙、計算機網(wǎng)絡、嵌入式物聯(lián)網(wǎng)、軟件測試、數(shù)據(jù)結(jié)構(gòu)與算法、音視頻開發(fā)、Flutter、IOS開發(fā)、PHP開發(fā)、.NET、安卓逆向、云計算文章來源地址http://www.zghlxwxcb.cn/news/detail-852899.html文章來源:http://www.zghlxwxcb.cn/news/detail-852899.html
AI人工智能、Android移動開發(fā)、AIGC大模型、C C#、Go語言、Java、Linux運維、云計算、MySQL、PMP、網(wǎng)絡安全、Python爬蟲、UE5、UI設計、Unity3D、Web前端開發(fā)、產(chǎn)品經(jīng)理、車載開發(fā)、大數(shù)據(jù)、鴻蒙、計算機網(wǎng)絡、嵌入式物聯(lián)網(wǎng)、軟件測試、數(shù)據(jù)結(jié)構(gòu)與算法、音視頻開發(fā)、Flutter、IOS開發(fā)、PHP開發(fā)、.NET、安卓逆向、云計算
到了這里,關(guān)于安卓高級工程師面試題,Android 儀器化單元測試(1),ndk開發(fā)入門的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!