最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

How to use Cuckoo in a Swift Local Package - Stack Overflow

programmeradmin4浏览0评论

I'm trying to break down a project into small local packages with their respective tests. I couldn't find any examples on how to use Cuckoo in such a scenario. Should I bundle a Cuckoofile for each local package? Appreciate your suggestions.

I'm trying to break down a project into small local packages with their respective tests. I couldn't find any examples on how to use Cuckoo in such a scenario. Should I bundle a Cuckoofile for each local package? Appreciate your suggestions.

Share Improve this question edited 21 hours ago David Pasztor 54.7k9 gold badges96 silver badges127 bronze badges asked yesterday James SelvakumarJames Selvakumar 2,8392 gold badges26 silver badges29 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

To integrate Cuckoo into a Local Swift Package, I had to define a Cuckoofile.toml in the root of the local package like this:

[modules.MyPackage]
  output = "Tests/MyPackageTests/GeneratedMocks.swift"
  imports = ["MyPackage"]
  sources = [
     "Sources/MyPackage/*.swift",
  ]

I also had to define the Cuckoo plugin in MyPackage's Package.swift.

import PackageDescription

let package = Package(
    name: "MyPackage",
    products: [
        // Products define the executables and libraries a package produces, making them visible to other packages.
        .library(
            name: "MyPackage",
            targets: ["MyPackage"]),
    ],
    dependencies: [
        .package(url: "https://github/Quick/Quick.git", from: "7.0.0"),
        .package(url: "https://github/Quick/Nimble.git", from: "12.0.0"),
        .package(url: "https://github/Brightify/Cuckoo.git", from: "2.0.0")
    ],
    targets: [
        // Targets are the basic building blocks of a package, defining a module or a test suite.
        // Targets can depend on other targets in this package and products from dependencies.
        .target(
            name: "MyPackage"),
        .testTarget(
            name: "MyPackageTests",
            dependencies: ["MyPackage", "Quick", "Nimble", "Cuckoo"],
            plugins: [
                .plugin(name: "CuckooPluginSingleFile", package: "Cuckoo")
            ]
        ),
    ]
)

Then when I ran the tests, my build failed. As I observed the build log, I saw a link to enable this plugin. I clicked it to enable and then the mocks were generated.

发布评论

评论列表(0)

  1. 暂无评论