Skip to content

Commit

Permalink
PR Feedback, ensure it works using sample projects
Browse files Browse the repository at this point in the history
  • Loading branch information
justinseanmartin committed Sep 18, 2017
1 parent eac6fd8 commit 70177a9
Show file tree
Hide file tree
Showing 9 changed files with 146 additions and 35 deletions.
14 changes: 13 additions & 1 deletion Classes/KIFSystemTestActor.h
Expand Up @@ -10,12 +10,24 @@
#import "KIFTestActor.h"
#import <UIKit/UIKit.h>

#ifdef __cplusplus

#define systemTester KIFActorWithClass(KIFSystemTestActor)

// The symbol `system` collides with the cstdlib for compiling C++. Leaving it available for compatibility reasons.
// This will be removed with the next major KIF release, please start using `systemTester` instead.
#ifndef __cplusplus

#if DEPRECATE_KIF_SYSTEM
// Add `-DDEPRECATE_KIF_SYSTEM=1` to OTHER_CFLAGS if you'd like to prevent usage of the `system` macro.
@class KIFSystemTestActor;
KIFSystemTestActor *_KIF_system() __attribute__((deprecated("Use of `system` has been deprecated; Use `systemTester` instead.")));
#define system _KIF_system()
#else
#define system KIFActorWithClass(KIFSystemTestActor)
#endif

#endif

@interface KIFSystemTestActor : KIFTestActor

/*!
Expand Down
Expand Up @@ -2,15 +2,19 @@
// See the LICENSE file distributed with this work for the terms under
// which Square, Inc. licenses this file to you.

#import <KIF/KIF.h>
#import "TestRobot.h"


@interface KIFUITestActor (BasicCalculator)
@interface BasicCalculatorRobot : TestRobot

- (void)enterValue1:(NSString *)value1 value2:(NSString *)value2 operation:(NSString *)operation;
- (void)enterValue1:(NSString *)value;
- (void)enterValue2:(NSString *)value;
- (void)setOperation:(NSString *)operation;
- (void)enterValue1:(NSString *)value1 value2:(NSString *)value2 operation:(NSString *)operation;

- (void)waitForResult:(NSString *)result;

@end


extern BasicCalculatorRobot *basicCalculatorRobot(KIFTestCase *testCase);
Expand Up @@ -2,36 +2,46 @@
// See the LICENSE file distributed with this work for the terms under
// which Square, Inc. licenses this file to you.

#import "KIFUITestActor+BasicCalculator.h"
#import <KIF/KIF.h>

#import "BasicCalculatorRobot.h"

@implementation KIFUITestActor (BasicCalculator)

- (void)enterValue1:(NSString *)value
@implementation BasicCalculatorRobot

#pragma mark - Public Methods

- (void)enterValue1:(NSString *)value1 value2:(NSString *)value2 operation:(NSString *)operation
{
[self clearTextFromAndThenEnterText:value intoViewWithAccessibilityLabel:@"First Number"];
[self enterValue1:value1];
[self enterValue2:value2];
[self setOperation:operation];
}

- (void)enterValue2:(NSString *)value
- (void)enterValue1:(NSString *)value
{
[self clearTextFromAndThenEnterText:value intoViewWithAccessibilityLabel:@"Second Number"];
[[viewTester usingLabel:@"First Number"] clearAndEnterText:value];
}

- (void)setOperation:(NSString *)operation
- (void)enterValue2:(NSString *)value
{
[self tapViewWithAccessibilityLabel:operation];
[[viewTester usingLabel:@"Second Number"] clearAndEnterText:value];
}

- (void)enterValue1:(NSString *)value1 value2:(NSString *)value2 operation:(NSString *)operation
- (void)setOperation:(NSString *)operation
{
[self enterValue1:value1];
[self enterValue2:value2];
[self setOperation:operation];
[[viewTester usingLabel:operation] tap];
}

- (void)waitForResult:(NSString *)result
{
[self waitForViewWithAccessibilityLabel:result];
[[viewTester usingLabel:result] waitForView];
}

@end


BasicCalculatorRobot *basicCalculatorRobot(KIFTestCase *testCase)
{
return [[BasicCalculatorRobot alloc] initWithTestCase:testCase];
}
Expand Up @@ -9,7 +9,7 @@

@import KIF;

#import "KIFUITestActor+BasicCalculator.h"
#import "BasicCalculatorRobot.h"


@interface BasicCalculatorTests : KIFTestCase
Expand All @@ -26,41 +26,41 @@ - (void)beforeAll
KIFTestActor.defaultAnimationStabilizationTimeout = 0.1;
KIFTestActor.defaultAnimationWaitingTimeout = 2.0;

[tester tapViewWithAccessibilityLabel:@"Basic Calculator" traits:UIAccessibilityTraitButton];
[[[viewTester usingLabel:@"Basic Calculator"] usingTraits:UIAccessibilityTraitButton] tap];
}

- (void)afterAll
{
[tester tapViewWithAccessibilityLabel:@"Home" traits:UIAccessibilityTraitButton];
[[[viewTester usingLabel:@"Home"] usingTraits:UIAccessibilityTraitButton] tap];
}

- (void)testAddition
{
[tester enterValue1:@"100" value2:@"11.11111" operation:@"Add"];
[tester waitForResult:@"111.11111000"];
[basicCalculatorRobot(self) enterValue1:@"100" value2:@"11.11111" operation:@"Add"];
[basicCalculatorRobot(self) waitForResult:@"111.11111000"];
}

- (void)testSubtraction
{
[tester enterValue1:@"200" value2:@"0.1" operation:@"Subtract"];
[tester waitForResult:@"199.90000000"];
[basicCalculatorRobot(self) enterValue1:@"200" value2:@"0.1" operation:@"Subtract"];
[basicCalculatorRobot(self) waitForResult:@"199.90000000"];
}

- (void)testMultiplication
{
[tester enterValue1:@"11.000" value2:@"1.1" operation:@"Multiply"];
[tester waitForResult:@"12.10000000"];
[basicCalculatorRobot(self) enterValue1:@"11.000" value2:@"1.1" operation:@"Multiply"];
[basicCalculatorRobot(self) waitForResult:@"12.10000000"];
}

- (void)testDivision
{
[tester enterValue1:@"5.000" value2:@"2" operation:@"Divide"];
[tester waitForResult:@"2.50000000"];
[basicCalculatorRobot(self) enterValue1:@"5.000" value2:@"2" operation:@"Divide"];
[basicCalculatorRobot(self) waitForResult:@"2.50000000"];
}

- (void)testToFail
{
[tester fail];
[viewTester fail];
NSLog(@"This line never executes.");
}

Expand Down
21 changes: 21 additions & 0 deletions Documentation/Examples/Calculator/Acceptance Tests/TestRobot.h
@@ -0,0 +1,21 @@
//
// TestRobot.h
// Calculator
//
// Created by Justin Martin on 9/18/17.
// Copyright © 2017 SSK Development. All rights reserved.
//

#import <Foundation/Foundation.h>


@interface TestRobot : NSObject <KIFTestActorDelegate>

- (instancetype)initWithTestCase:(KIFTestCase *)testCase;

#pragma mark - Unavailable

+ (instancetype)new NS_UNAVAILABLE;
- (instancetype)init NS_UNAVAILABLE;

@end
46 changes: 46 additions & 0 deletions Documentation/Examples/Calculator/Acceptance Tests/TestRobot.m
@@ -0,0 +1,46 @@
//
// TestRobot.m
// Calculator
//
// Created by Justin Martin on 9/18/17.
// Copyright © 2017 SSK Development. All rights reserved.
//

#import <KIF/KIF.h>

#import "TestRobot.h"


@interface TestRobot ()

@property (nonatomic, readwrite, weak) KIFTestCase *testCase;

@end


@implementation TestRobot

- (instancetype)initWithTestCase:(KIFTestCase *)testCase;
{
self = [super init];
if (!self) {
return nil;
}

_testCase = testCase;
return self;
}

#pragma mark - KIFTestActorDelegate

- (void)failWithException:(NSException *)exception stopTest:(BOOL)stop;
{
[self.testCase failWithException:exception stopTest:stop];
}

- (void)failWithExceptions:(NSArray *)exceptions stopTest:(BOOL)stop;
{
[self.testCase failWithExceptions:exceptions stopTest:stop];
}

@end
Expand Up @@ -9,7 +9,8 @@
/* Begin PBXBuildFile section */
62F81B511EBBE965009B2400 /* KIF.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 62F81B3C1EBBE917009B2400 /* KIF.framework */; };
62F81B521EBBE976009B2400 /* BasicCalculatorTests.m in Sources */ = {isa = PBXBuildFile; fileRef = EB4C315F167BAE6100E31109 /* BasicCalculatorTests.m */; };
62F81B5D1EBBEB6B009B2400 /* KIFUITestActor+BasicCalculator.m in Sources */ = {isa = PBXBuildFile; fileRef = 62F81B5C1EBBEB6B009B2400 /* KIFUITestActor+BasicCalculator.m */; };
62F81B5D1EBBEB6B009B2400 /* BasicCalculatorRobot.m in Sources */ = {isa = PBXBuildFile; fileRef = 62F81B5C1EBBEB6B009B2400 /* BasicCalculatorRobot.m */; };
62F972EB1F708273003EFFDA /* TestRobot.m in Sources */ = {isa = PBXBuildFile; fileRef = 62F972EA1F708273003EFFDA /* TestRobot.m */; };
EB4C30DE167B9E3A00E31109 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = EB4C30DD167B9E3A00E31109 /* UIKit.framework */; };
EB4C30E0167B9E3A00E31109 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = EB4C30DF167B9E3A00E31109 /* Foundation.framework */; };
EB4C30E2167B9E3A00E31109 /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = EB4C30E1167B9E3A00E31109 /* CoreGraphics.framework */; };
Expand Down Expand Up @@ -88,8 +89,10 @@

/* Begin PBXFileReference section */
62F81B451EBBE925009B2400 /* Acceptance Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "Acceptance Tests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; };
62F81B5B1EBBEB6B009B2400 /* KIFUITestActor+BasicCalculator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "KIFUITestActor+BasicCalculator.h"; sourceTree = "<group>"; };
62F81B5C1EBBEB6B009B2400 /* KIFUITestActor+BasicCalculator.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "KIFUITestActor+BasicCalculator.m"; sourceTree = "<group>"; };
62F81B5B1EBBEB6B009B2400 /* BasicCalculatorRobot.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BasicCalculatorRobot.h; sourceTree = "<group>"; };
62F81B5C1EBBEB6B009B2400 /* BasicCalculatorRobot.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BasicCalculatorRobot.m; sourceTree = "<group>"; };
62F972E91F708273003EFFDA /* TestRobot.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TestRobot.h; sourceTree = "<group>"; };
62F972EA1F708273003EFFDA /* TestRobot.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TestRobot.m; sourceTree = "<group>"; };
A8892FF71684F0A400FC7C63 /* KIF.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = KIF.xcodeproj; path = ../../../KIF.xcodeproj; sourceTree = "<group>"; };
EB4C30D9167B9E3A00E31109 /* Calculator.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Calculator.app; sourceTree = BUILT_PRODUCTS_DIR; };
EB4C30DD167B9E3A00E31109 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; };
Expand Down Expand Up @@ -225,8 +228,10 @@
children = (
EB4C3144167BA79700E31109 /* Supporting Files */,
EB4C315F167BAE6100E31109 /* BasicCalculatorTests.m */,
62F81B5B1EBBEB6B009B2400 /* KIFUITestActor+BasicCalculator.h */,
62F81B5C1EBBEB6B009B2400 /* KIFUITestActor+BasicCalculator.m */,
62F81B5B1EBBEB6B009B2400 /* BasicCalculatorRobot.h */,
62F81B5C1EBBEB6B009B2400 /* BasicCalculatorRobot.m */,
62F972E91F708273003EFFDA /* TestRobot.h */,
62F972EA1F708273003EFFDA /* TestRobot.m */,
);
path = "Acceptance Tests";
sourceTree = "<group>";
Expand Down Expand Up @@ -393,8 +398,9 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
62F81B5D1EBBEB6B009B2400 /* KIFUITestActor+BasicCalculator.m in Sources */,
62F81B5D1EBBEB6B009B2400 /* BasicCalculatorRobot.m in Sources */,
62F81B521EBBE976009B2400 /* BasicCalculatorTests.m in Sources */,
62F972EB1F708273003EFFDA /* TestRobot.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -481,6 +487,10 @@
INFOPLIST_FILE = "Acceptance Tests/Acceptance Tests-Info.plist";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
MTL_ENABLE_DEBUG_INFO = YES;
OTHER_CFLAGS = (
"-DDEPRECATE_KIF_SYSTEM=1",
"-DDEPRECATE_KIF_TESTER=1",
);
OTHER_LDFLAGS = "-ObjC";
PRODUCT_BUNDLE_IDENTIFIER = "com.squareup.Acceptance-Tests";
PRODUCT_NAME = "$(TARGET_NAME)";
Expand Down
Expand Up @@ -518,6 +518,10 @@
);
INFOPLIST_FILE = "Testable SwiftTests/Info.plist";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
OTHER_CFLAGS = (
"-DDEPRECATE_KIF_SYSTEM=1",
"-DDEPRECATE_KIF_TESTER=1",
);
OTHER_LDFLAGS = (
"$(inherited)",
"-framework",
Expand Down
Expand Up @@ -471,6 +471,10 @@
INFOPLIST_FILE = "Acceptance Tests/Acceptance Tests-Info.plist";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
MTL_ENABLE_DEBUG_INFO = YES;
OTHER_CFLAGS = (
"-DDEPRECATE_KIF_SYSTEM=1",
"-DDEPRECATE_KIF_TESTER=1",
);
OTHER_LDFLAGS = "-ObjC";
PRODUCT_BUNDLE_IDENTIFIER = "com.squareup.Acceptance-Tests";
PRODUCT_NAME = "$(TARGET_NAME)";
Expand Down

0 comments on commit 70177a9

Please sign in to comment.