أين توجد الاختبارات: commonTest وما شابهها
مجموعات المصادر للاختبارات المشتركة والخاصة بالمنصة
أين توجد الاختبارات: commonTest وما شابهها درس مجاني في Kotlin Multiplatform Academy على CoddyKit. هذا هو الدرس 4 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في Kotlin Multiplatform Academy، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة Kotlin Multiplatform Academy 4 دروس في المجموع.
بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.
Tests Get Source Sets Too
Just like your main code, tests live in their own source sets, mirroring commonMain, androidMain and iosMain.
Meet commonTest
commonTest holds tests that run on every platform. Write a test once and verify your shared logic everywhere. ✅
The kotlin.test Library
Common tests use the multiplatform kotlin.test library, which gives you assertions that work on all targets.
commonTest.dependencies {
implementation(kotlin("test"))
}A First Shared Test
A common test reads like any unit test, using a portable assertEquals to check shared behavior.
@Test
fun greetsName() {
assertEquals("Hi, Sam", greet("Sam"))
}androidUnitTest
Need a JVM-only test? Put it in androidUnitTest, where you can use JUnit and Android-specific helpers.
iosTest
iOS-specific tests live in iosTest. They run on the simulator using Kotlin/Native's test runner.
Common Tests Run On All
A test in commonTest executes on both the Android and iOS test tasks, catching platform differences early.
Run the Android Suite
From the terminal, a single Gradle task runs the JVM-side tests, including the common ones.
./gradlew :shared:testDebugUnitTestRun the iOS Suite
Another task runs the same shared tests on the iOS simulator target, confirming parity.
./gradlew :shared:iosSimulatorArm64TestWhy Test in Common
Testing shared logic in commonTest means one suite guards both apps, so a fix is proven on every platform at once.
Keep Tests Where Code Is
Mirror your main sets: common logic gets common tests, platform code gets platform tests. The structure stays predictable.
Quick Check
Pick the right test home.
Recap
Tests mirror the source sets: commonTest for shared, androidUnitTest and iosTest for platform-specific checks.
الأسئلة الشائعة
هل درس «أين توجد الاختبارات: commonTest وما شابهها» مجاني؟
نعم — نص درس «أين توجد الاختبارات: commonTest وما شابهها» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة Kotlin Multiplatform Academy، انتقل إلى CoddyKit PRO. تتضمن دورة Kotlin Multiplatform Academy 4 دروس في المجموع.
ماذا ستتعلم في «أين توجد الاختبارات: commonTest وما شابهها»؟
مجموعات المصادر للاختبارات المشتركة والخاصة بالمنصة تتمرن على Kotlin Multiplatform Academy مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.
هل أحتاج إلى خبرة سابقة لأبدأ Kotlin Multiplatform Academy؟
لا تُشترط خبرة سابقة. Kotlin Multiplatform Academy على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 4 من أصل 4.
كم من الوقت يستغرق درس «أين توجد الاختبارات: commonTest وما شابهها»؟
معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.
هل يمكنني كتابة وتشغيل أكواد في درس Kotlin Multiplatform Academy هذا؟
نعم. كل درس في Kotlin Multiplatform Academy يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.
جميع الدروس في هذه الدورة
- الوحدة المشتركة مقابل وحدات التطبيق
- commonMain وandroidMain وiosMain
- قراءة build.gradle.kts المشترك
- أين توجد الاختبارات: commonTest وما شابهها