Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
K
kotlin_sample
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
jiangyh
kotlin_sample
Commits
eedf81cd
You need to sign in or sign up before continuing.
Commit
eedf81cd
authored
Feb 12, 2026
by
jiangyh
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
更新readme
parent
ae1d29d1
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
55 additions
and
0 deletions
+55
-0
README.md
README.md
+55
-0
No files found.
README.md
View file @
eedf81cd
...
@@ -273,6 +273,61 @@ find harmonyapp/entry -name "libarith.a"
...
@@ -273,6 +273,61 @@ find harmonyapp/entry -name "libarith.a"
- Kotlin 文案:`
getKotlinUiText()
` 的返回内容
- Kotlin 文案:`
getKotlinUiText()
` 的返回内容
- 静态库加法结果:`
add(2, 3) = 5
`
- 静态库加法结果:`
add(2, 3) = 5
`
### 公共测试与鸿蒙端单元测试
工程中对 expect/actual 的测试分为两部分:公共测试(commonTest)与鸿蒙端测试(ohosArm64Test)。
- **公共测试 (PlatformExpectActualCommonTest)**
- 测试代码位置:`
composeApp/src/commonTest/kotlin/com/example/testdemo/PlatformExpectActualCommonTest.kt
`
- 用途:验证 `
getPlatform().name
` 在所有平台上的实现都返回非空字符串,属于平台无关的业务校验。
- IDE 运行方式:
- 在 Android Studio / DevEco 中打开上述文件,点击类名或方法左侧的绿色三角即可运行。
- Gradle 命令行运行方式(以 Android/JVM 为载体执行 commonTest):
```bash
# 调试构建下的单元测试(推荐)
./gradlew :composeApp:testDebugUnitTest
# 或运行发布构建下的单元测试
./gradlew :composeApp:testReleaseUnitTest
# 或执行完整检查(包含单元测试)
./gradlew :composeApp:check
```
- 上述命令会自动把 `
commonTest
` 源集中的用例整合到 Android/JVM 的测试任务中执行。
- **鸿蒙端测试 (OhosPlatformTest)**
- 测试代码位置:`
composeApp/src/ohosArm64Test/kotlin/com/example/testdemo/OhosPlatformTest.kt
`
- 用途:在真实的 HarmonyOS 设备上验证 `
getPlatform().name
` 的鸿蒙实现,并观察日志输出。
- 构建与运行步骤:
1. **构建测试二进制**:
```bash
./gradlew :composeApp:linkDebugTestOhosArm64
```
产物路径:`
composeApp/build/bin/ohosArm64/debugTest/test.kexe
`
2. **推送到设备并运行**(需连接真机或模拟器):
```bash
# 推送
hdc file send composeApp/build/bin/ohosArm64/debugTest/test.kexe /data/local/tmp/test.kexe
# 赋权并运行
hdc shell chmod +x /data/local/tmp/test.kexe
hdc shell /data/local/tmp/test.kexe
```
3. **查看结果**:
终端应直接输出测试日志,例如:
```text
OhosPlatformTest: Running testGetPlatform
OhosPlatformTest: Platform name: HarmonyOS
OhosPlatformTest: Test finished
```
- 注意事项:
- 当前实现使用 Kotlin 的 `
println
` 输出日志,通过 `
hdc shell /data/local/tmp/test.kexe
` 可以直接看到标准输出。
- 若需要将日志统一到 HiLog,可在后续替换为 Hilog 封装(例如链接 `
libhilog.so
` 并调用 `
OH_LOG_Print
`)。
### 类型声明与编译规则(ArkTS)
### 类型声明与编译规则(ArkTS)
- 模块类型文件
- 模块类型文件
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment