Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add UIKit screenshot tests for layout's Spacer #1542

Merged
merged 1 commit into from
Oct 4, 2023

Conversation

JakeWharton
Copy link
Collaborator

This adds the start of a new setup for hosting Kotlin tests within an iOS project so that we can use a Swift screenshot testing library. For now you have to prefix your test functions with "test" and any before/after-annotated functions need to be named "setUp" and "tearDown" (very JUnit 3). We also do not support anything JVM-specific like rules or parameterization for now.

Refs #1343

@JakeWharton JakeWharton force-pushed the jw.layout-uiview-screenshot-testing.2023-09-29 branch from 534935c to 320d8d7 Compare September 29, 2023 20:14
Comment on lines +4 to +9
/**
* An abstract base class for hosting Kotlin test classes in Swift projects.
*
* Subclasses must override `initTest(name:)` to create instances of `KotlinType`.
*/
open class KotlinHostingXCTestCase<KotlinTest>: KotlinHostingXCTestCaseHelper where KotlinTest: NSObject {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here be crimes

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🍿

Comment on lines +5 to +9
final class UIViewSpacerTestHost: KotlinHostingXCTestCase<UIViewSpacerTest> {
override class func initTest(name: String) -> UIViewSpacerTest {
return UIViewSpacerTest(callback: Callback(named: name))
}
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But this is 👨‍🍳💋

Base automatically changed from jw.stuff.2023-09-28 to trunk September 29, 2023 20:18
This adds the start of a new setup for hosting Kotlin tests within an iOS project so that we can use a Swift screenshot testing library. For now you have to prefix your test functions with "test" and any before/after-annotated functions need to
be named "setUp" and "tearDown" (very JUnit 3). We also do not support anything JVM-specific like rules or parameterization for now.
@JakeWharton JakeWharton force-pushed the jw.layout-uiview-screenshot-testing.2023-09-29 branch from 320d8d7 to 3d4411e Compare September 29, 2023 20:19
Copy link
Member

@colinrtwhite colinrtwhite left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

Comment on lines +4 to +9
/**
* An abstract base class for hosting Kotlin test classes in Swift projects.
*
* Subclasses must override `initTest(name:)` to create instances of `KotlinType`.
*/
open class KotlinHostingXCTestCase<KotlinTest>: KotlinHostingXCTestCaseHelper where KotlinTest: NSObject {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🍿


private static func createTestMethod(target: KotlinTest, selector: Selector) {
let block: @convention(block) () -> Void = {
if target.responds(to: #selector(setUp)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oooooh

if target.responds(to: #selector(setUp)) {
target.perform(#selector(setUp))
}
defer {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

neat

@JakeWharton JakeWharton merged commit 1ba5834 into trunk Oct 4, 2023
8 checks passed
@JakeWharton JakeWharton deleted the jw.layout-uiview-screenshot-testing.2023-09-29 branch October 4, 2023 16:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants