<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??碼云GVP開源項目 12k star Uniapp+ElementUI 功能強大 支持多語言、二開方便! 廣告
                目錄與包的結構無需匹配:源代碼可以在文件系統的任意位置。 如下示例 ![](https://box.kancloud.cn/00b6d48bb008a68e24dce158cbce0330_461x624.png) 在測試源代碼目錄src/test/kotlin 下面新建一個包,跟 src/main/kotlin 下的包是同一個包`package com.easy.kotlin ` 然后,在此包下面新建一個測試類PackageDemoTest * `PackageDemo.kt`在`src/main/kotlin`下的包`package com.easy.kotlin `中 * `DefaultPackageDemo.kt`在在`src/main/kotlin`中 * 測試類PackageDemoTest在`src/test/kotlin`下的包`package com.easy.kotlin `中 * 測試類DefaultPackageDemoTest在`src/test/kotlin`中 **PackageDemo.kt**代碼如下 ``` package com.wsc.study fun main(args: Array<String>) { println("hello kotlin") } fun what(){ println("This is WHAT ?") } class Motorbike{ fun drive(){ println("Drive The Motorbike .........") } } ``` **測試類PackageDemoTest**代碼如下 ``` package com.wsc.study import org.junit.Test import org.junit.runner.RunWith import org.junit.runners.JUnit4 import now import Car @RunWith(JUnit4::class) class PackageDemoTest { @Test fun testWhat(){ what() } @Test fun testDriveMotorbike(){ val motorbike=Motorbike() motorbike.drive() } @Test fun testDefaultPackage(){ now() val car=Car() car.drive() } } ``` 上面我們使用JUnit4測試框架。在 build.gradle 中的依賴是 ~~~ testCompile group: 'junit', name: 'junit', version: '4.12' ~~~ 右擊測試類PackageDemoTest,點擊執行 ![](https://box.kancloud.cn/368b0182c765c42f3382292ca6cd71d1_833x716.png) 運行結果如下 ![](https://box.kancloud.cn/c1364accff4ad4a947f6e831ff9f93e4_1093x847.png) 另外,如果我們不定義package命令空間,則默認在根級目錄。例如直接在 src/main/kotlin 源代碼目錄下面新建 **DefaultPackageDemo.kt** 類 ``` import java.util.* fun now(){ println("Now Date is:"+Date()) } class Car{ fun drive(){ println("Drive The Car....") } } ``` 同樣在 src/test/kotlin 目錄下面新建測試類**DefaultPackageDemoTest** ``` import org.junit.Test import org.junit.runner.RunWith import org.junit.runners.JUnit4 @RunWith(JUnit4::class) class DefaultPackageDemoTest { @Test fun testDefaultPackage(){ now() val car=Car() car.drive() } } ``` 右擊測試類DefaultPackageDemoTest,點擊執行,運行結果如下 ![](https://box.kancloud.cn/9cce23d4ec0942cd25e53cc0adaf2141_1100x692.png) 我們不需要import now() 函數和 Car 類,可以直接調用。 如果我們在` src/test/kotlin/com/easy/kotlin/PackageDemoTest.kt` 測試類里面調用 now() 函數和 Car 類, 我們按照下面的方式import ``` import now import Car ``` 如果不在同一個package下面,我們就需要import對應的類和函數。例如,我們在src/test/kotlin 目錄下新建一個`package com.easy.kotlin.test `, 使用 `package com.easy.kotlin `下面的類和函數,如下圖所示 ![](https://box.kancloud.cn/cd169209a0a58714a7b387e62b57ab15_475x405.png) 我們在src/test/kotlin的包package com.easy.kotlin下又新建一個包test,即`package com.easy.kotlin.test `,在這個包下我們創建**測試類PackageDemoTest2** ``` package com.wsc.study.test import com.wsc.study.Motorbike import com.wsc.study.what import org.junit.Test import org.junit.runner.RunWith import org.junit.runners.JUnit4 @RunWith(JUnit4::class) class PackageDemoTest2 { @Test fun testWhat(){ what() } @Test fun testDriveMotorbike(){ val motorbike=Motorbike() motorbike.drive() } } ``` 測試類PackageDemoTest2類使用到了`package com.easy.kotlin `下面的類Motorbike和函數what(),我們使用`import com.wsc.study.Motorbike `導入類,直接使用`import com.wsc.study.what `導入包級函數。
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看