494 sao GitHub và vẫn tăng — kishikawakatsumi/swift-power-assert là dự án Swift mà TopGit đang theo dõi trên nền tảng. Power Assert in Swift.
Tóm tắt dựng từ metadata GitHub của chính dự án — chưa có bài review TopGit. Trang sẽ tự động cập nhật khi bài review đầy đủ được xuất bản.
VÌ SAO CHƯA CÓ REVIEW
TopGit viết bài đầy đủ cho repo có nhiều sao nhất và được yêu cầu nhiều nhất. Trang này là snapshot trong thời gian chờ — xem README gốc ở tab READ ME.
Power asserts (also known as diagrammed assertions) augment your assertion failures with information about the values produced during evaluation of a condition, and present it in an easily digestible form. Power asserts are a popular feature of Spock (and later the entire Groovy language independent of Spock), ScalaTest and Expecty.
Power asserts provide descriptive assertion messages for your tests, like the following examples:
Experience the library in action with our online playground! :sparkles: Click here to access the interactive demo.
Why Power Assert?
When writing tests, we need to use different assertion functions. With Power Assert you only use the #assert() function. There are many
Assertion APIs, no need to remember them. Just create an expression that returns a boolean value and Power Assert will automatically display rich error information.
Getting Started
Requirements:
Swift 5.9 or later
Xcode 15.0 or later
For Xcode Project
To see PowerAssert in action, go to the Examples directory and run xcodebuild test ....
$ cd Examples/XcodeProject/
$ xcodebuild test -scheme MyApp -destination 'platform=iOS Simulator,name=iPhone 14 Pro,OS=17.0' -parallel-testing-enabled NO
The parameter -parallel-testing-enabled NO is required. Due to recent changes in Xcode, parallel testing is now turned on by default and test messages are no longer output to the console. Therefore, to see assertion messages in the console, disable parallel testing. When parallel testing is enabled, all console logs can be viewed from the result bundle.
Or set the following UserDefaults. This option allows console output even if parallel testing is enabled.
To see PowerAssert in action, go to the Examples directory and run swift test.
$ cd Examples/SwiftPackage/
$ swift test
See the following results?
...
Test Suite 'All tests' started at 2023-04-05 07:17:58.800
Test Suite 'swift-power-assert-examplePackageTests.xctest' started at 2023-04-05 07:17:58.801
Test Suite 'PowerAssertTests' started at 2023-04-05 07:17:58.801
Test Case '-[ExampleTests.PowerAssertTests testExample]' started.
/swift-power-assert/Example/"ExampleTests/ExampleTests.swift":8: error: -[ExampleTests.PowerAssertTests testExample] : failed -
#assert(a * b == 91)
│ │ │ │ │
│ │ 9 │ 91
│ 90 false
10
[Int] a
=> 10
[Int] b
=> 9
[Int] a * b
=> 90
[Int] 91
=> 91
/swift-power-assert/Example/"ExampleTests/ExampleTests.swift":11: error: -[ExampleTests.PowerAssertTests testExample] : failed -
#assert(xs.contains(4))
│ │ │
│ false 4
[1, 2, 3]
...
Modify the code in Example/Tests/ExampleTests.swift to try different patterns you like.
Usage
To use Swift Power Assert in your library or application, first add swift-power-assert to your project.
For the Xcode project, add the swift-power-assert library as a package dependency.
Select PowerAssert as the Package Product and specify the Test Bundle as the target to add.
For the Swift package, configure Package.swift as follows:
Next, you can use Power Assert in your tests with the #assert() macro.
// MyLibraryTests.swift
import XCTest
import PowerAssert
@testable import MyLibrary
final class MyLibraryTests: XCTestCase {
func testExample() {
let a = 7
let b = 4
let c = 12
#assert(max(a, b) == c)
}
}
Concurrency (async/await) support
Swift Power Assert library allows you to write assertions with async/await expressions directly. Here's a sample code demonstrating its seamless support for async/await:
func testConcurrency() async {
let ok = "OK"
#assert(await upload(content: "example") == ok)
}
For use on CI
For unattended use (e.g. on CI), you can disable the package validation dialog by
individually passing -skipMacroValidation to xcodebuild or
globally setting defaults write com.apple.dt.Xcode IDESkipMacroFingerprintValidation -bool YES
for that user.
Frequently Asked Questions
Q: Assert failure messages are not displayed.
If you are running your tests from the command line using the xcodebuild test ... command, disable parallel testing. Due to recent changes in Xcode, detailed test logs are not output to the console when parallel testing is enabled. Use the following options to disable parallel testing
-parallel-testing-enabled NO
Alternatively, set the following UserDefaults. This option enables detailed messages to be output to the console even parallel testing enabled.
Q: I want to display the result even if the test is successful (i.e. the expression in the #assert() function evaluates to true).
A: By default, the #assert() function does not display the result if the expression evaluates to true, because the test was successful. To always print the result, set the verbose argument to true.
For example:
#assert(x == y, verbose: true)
Q: I want to know how the compiler actually expanded the macro.
A: You can use the -dump-macro-expansions option to dump the macro expansion.
For example:
$ cd Examples/SwiftPackage/
$ swift test -Xswiftc -Xfrontend -Xswiftc -dump-macro-expansions
If you run the above with the -dump-macro-expansions option, you will get the following output.
Open source projects thrive on the generosity and support of people like you. If you find this project valuable, please consider extending your support. Contributing to the project not only sustains its growth, but also helps drive innovation and improve its features.
To support this project, you can become a sponsor through GitHub Sponsors. Your contribution will be greatly appreciated and will help keep the project alive and thriving. Thanks for your consideration! :heart:
kishikawakatsumi/swift-power-assert thuộc nhóm Mobile trên TopGit, cùng 3 topic GitHub. Trang Trending và Topics liệt kê các repo cùng số sao và cùng ngôn ngữ để so sánh.
Đọc thêm về kishikawakatsumi/swift-power-assert ở đâu?
Trang TopGit này là một snapshot — tab "Readme" hiển thị nguyên văn README của repo (đã bỏ link, giữ ảnh). Repo GitHub ở github.com/kishikawakatsumi/swift-power-assert là nguồn chính thức.
kishikawakatsumi/swift-power-assert có bao nhiêu sao?
kishikawakatsumi/swift-power-assert có 494 sao GitHub — tải lại trang để xem số mới nhất, hoặc xem trực tiếp github.com/kishikawakatsumi/swift-power-assert. TopGit phản chiếu số sao của GitHub nhưng không cam kết đến từng phút.
kishikawakatsumi/swift-power-assert có những chủ đề gì?
GitHub topics của kishikawakatsumi/swift-power-assert: "power-assert", "swift", "testing". TopGit xếp repo vào nhóm Mobile.
kishikawakatsumi/swift-power-assert có phải mã nguồn mở không?
Có — kishikawakatsumi/swift-power-assert phát hành theo license MIT, nghĩa là mã nguồn mở để đọc, fork và (tùy license) tái sử dụng. Mã: github.com/kishikawakatsumi/swift-power-assert.
kishikawakatsumi/swift-power-assert có trang demo không?
Dự án có trang chủ ở https://power-assert.swiftfiddle.com/. Tab "Readme" ở trang này thường có ảnh chụp và hướng dẫn bắt đầu nhanh.
kishikawakatsumi/swift-power-assert còn đang phát triển không?
Commit gần nhất trên kishikawakatsumi/swift-power-assert là 7 ngày trước (theo timestamp GitHub). Repo có 12 fork — một chỉ báo về mức độ quan tâm của cộng đồng.
Đọc đầy đủ README ở tab phía trên.
Muốn nghe thêm một ý kiến về swift-power-assert?
Hỏi một AI đọc được trang này — một cú bấm là có ngay nhận định về swift-power-assert.