Kotlin多平台覆盖范围?

时间:2020-01-18 16:12:40

标签: testing kotlin code-coverage multiplatform

在Kotlin多平台项目的公共部分中是否有用于测量测试覆盖率的工具?我正在研究将Kotlin项目迁移到多平台。我是TDD开发人员,代码覆盖率达98%。 95%的人可以成为普通人。我在寻找放弃覆盖率指标吗?

2 个答案:

答案 0 :(得分:1)

我还有一个使用jacoco进行测试报道的多平台kotlin项目。

只需遵循此guide

但是如果您使用gradle kotlin dsl,则需要进行一些配置:

<?PHP
public function getBillItems($BillID){
        if($this->connected === true){
            try{
                $items = $this->connection->prepare("SELECT `items` FROM `bills` WHERE id=:id");
                $items->bindParam(":id",$BillID);
                $items->execute();
                return $items->fetchColumn();
            }
            catch(PDOException $e){
                if($this->errors === true){
                    return $this->error($e->getMessage());
                }else{
                    return false;
                }
            }
        }
    }
    public function getPrice($id,$codenumber){
        if($this->connected === true){
            try{
                $items = $this->connection->prepare("SELECT `items` FROM `bills` WHERE id=:id");
                $items->bindParam(":id",$id);
                $items->execute();
                $fetchedItems = $items->fetchColumn();
                $items = json_decode($fetchedItems);
                $array = array_column($items, null, 'codenumber');
                return $array[$codenumber]->price; 
            }
            catch(PDOException $e){
                if($this->errors === true){
                    return $this->error($e->getMessage());
                }else{
                    return false;
                }
            }
        }
    }
?>

运行以下命令将在您的Array ( [0] => stdClass Object ( [0] => 1 [1] => o4 [2] => Efexor [3] => Eklil [4] => 1 [5] => 30 [6] => 15 [7] => Phezer [8] => Venlafaxine [9] => [10] => 0 [11] => 2020-03-25 [12] => 2021-08-25 [13] => 1 [14] => 0 [15] => 0 [16] => caps [17] => ..\upload\Efexor.jpg [id] => 1 [qty] => 15 [Sale] => 1 [name] => Efexor [bonus] => 0 [price] => 30 [company] => Phezer [draftid] => 1 [discount] => 0 [imageurl] => ..\upload\Efexor.jpg [owned-com] => Eklil [pack-size] => 0 [codenumber] => o4 [chemicalcom] => Venlafaxine [dosage-form] => caps [concentration] => [expiration-date] => 2021-08-25 [production-date] => 2020-03-25 ) [1] => stdClass Object ( [0] => 2 [1] => [2] => Efexor [3] => Eklil [4] => 1 [5] => 15 [6] => 10 [7] => Phezer [8] => Venlafaxine [9] => [10] => 0 [11] => 2020-03-25 [12] => 2021-08-25 [13] => 0 [14] => 0 [15] => 0 [16] => caps [17] => ..\upload\Efexor.jpg [id] => 2 [qty] => 10 [Sale] => 0 [name] => Efexor [bonus] => 0 [price] => 15 [company] => Phezer [draftid] => 1 [discount] => 0 [imageurl] => ..\upload\Efexor.jpg [owned-com] => Eklil [pack-size] => 0 [codenumber] => [chemicalcom] => Venlafaxine [dosage-form] => caps [concentration] => [expiration-date] => 2021-08-25 [production-date] => 2020-03-25 ) [2] => stdClass Object ( [0] => 3 [1] => [2] => panadol [3] => com2 [4] => 1 [5] => 5 [6] => 12 [7] => GSK [8] => Paracetamol [9] => [10] => 0 [11] => 2020-04-09 [12] => 2021-02-09 [13] => 0 [14] => 0 [15] => 2 [16] => taps [17] => ..\upload\panadol.png [id] => 3 [qty] => 12 [Sale] => 0 [name] => panadol [bonus] => 2 [price] => 5 [company] => GSK [draftid] => 1 [discount] => 0 [imageurl] => ..\upload\panadol.png [owned-com] => com2 [pack-size] => 0 [codenumber] => [chemicalcom] => Paracetamol [dosage-form] => taps [concentration] => [expiration-date] => 2021-02-09 [production-date] => 2020-04-09 ) [3] => stdClass Object ( [0] => 4 [1] => codenumber [2] => name [3] => owned [4] => 1 [5] => 9 [6] => 1 [7] => gsk [8] => gscom [9] => 12mg [10] => 3 [11] => 2020-03-25 [12] => 2021-02-09 [13] => 1 [14] => 0 [15] => 0 [16] => caps [17] => ..\upload\panadol.png [id] => 4 [qty] => 1 [Sale] => 1 [name] => name [bonus] => 0 [price] => 9 [company] => gsk [draftid] => 1 [discount] => 0 [imageurl] => ..\upload\panadol.png [owned-com] => owned [pack-size] => 3 [codenumber] => codenumber [chemicalcom] => gscom [dosage-form] => caps [concentration] => 12mg [expiration-date] => 2021-02-09 [production-date] => 2020-03-25 ) [4] => stdClass Object ( [0] => 5 [1] => d322 [2] => fsdfds [3] => ewfwef [4] => 1 [5] => 3232 [6] => 222 [7] => none [8] => nonoe [9] => nonoe [10] => 12 [11] => 2020-03-25 [12] => 2021-02-09 [13] => 1 [14] => 0 [15] => 2 [16] => caps [17] => ..\upload\panadol.png [id] => 5 [qty] => 222 [Sale] => 1 [name] => fsdfds [bonus] => 2 [price] => 3232 [company] => none [draftid] => 1 [discount] => 0 [imageurl] => ..\upload\panadol.png [owned-com] => ewfwef [pack-size] => 12 [codenumber] => d322 [chemicalcom] => nonoe [dosage-form] => caps [concentration] => nonoe [expiration-date] => 2021-02-09 [production-date] => 2020-03-25 ) [5] => stdClass Object ( [0] => 6 [1] => 上生成报告

plugins {
    kotlin("multiplatform") version "1.3.72"
    id("java-library")
    jacoco
}

jacoco {
    toolVersion = "0.8.5"
}

tasks.jacocoTestReport {
    val coverageSourceDirs = arrayOf(
            "src/commonMain",
            "src/jvmMain"
    )

    val classFiles = File("${buildDir}/classes/kotlin/jvm/")
            .walkBottomUp()
            .toSet()
            }

    classDirectories.setFrom(classFiles)
    sourceDirectories.setFrom(files(coverageSourceDirs))

    executionData
            .setFrom(files("${buildDir}/jacoco/jvmTest.exec"))

    reports {
        xml.isEnabled = true
        html.isEnabled = true
    }
}

答案 1 :(得分:0)

AAFIK唯一能够测量Kotlin覆盖率的工具是Jetbrains IDEA。我几乎可以肯定,它也可以算出Kotlin MPP的覆盖范围,但是令人遗憾的是,我不知道将其插入CI管道的任何明智方法。

相关问题