2

I'm new to iOS, xcode, KIF framework, Objective C. And my first assignment is to write test code using KIF. It sure seems like it would be a lot easier if KIF had conditional statements.

Basically something like:

if ([tester existsViewWithAccessibilityLabel:@"Login"]) {
    [self login];
}
// continue with test in a known state

When you run one test at a time KIF exits the app after the test. If you run all your tests at once, it does not exit in between tests - requiring testers be very, very careful of the state of the application (which is very time consuming and not fun).

SilentNot
  • 1,661
  • 1
  • 16
  • 25
Gerry
  • 1,031
  • 1
  • 14
  • 30

3 Answers3

1

Testing frameworks typically don't implement if conditions as they already exist in their native form.
You can look at the testing framework's source code to find how it does the "If state checks". This will teach you to fish on how to do most things you may want to do (even if is not always a good idea to do them during a functional test). You could also look here: Can I check if a view exists on the screen with KIF?

Besides, your tests should be assertive in nature as follow the following workflow:

 given:
    the user has X state setup  
    (here you write code to assertively setup the state)

    It is OK and preferred to isolate your tests and setup
    the "given" state (e.g. set login name in the model directly without going
    through the UI) as long as you have covered that behavior in another test. 

    When:
    The user tries to do X
    (here you tap something etc..)

    Then:<br>
    The system should respond with Z
    (here you verify the system did what you need it) 
Community
  • 1
  • 1
SilentNot
  • 1,661
  • 1
  • 16
  • 25
  • The KIF framework "drives" the UI like a user - so the test code has no access to any of the UI elements or any other code at all. Unless you do things like add a singleton reference (or similar) you are basically blind to what's going on in the code. – Gerry May 23 '14 at 15:17
  • Nice clarification @Gerry – SilentNot May 23 '14 at 16:12
0

The first step in every test should be to reset the app to a known state, because it's the only way to guarantee repeatable testing. Once you start putting conditional code in the tests themselves, you are introducing unpredictability into the results.

Ian
  • 11,280
  • 3
  • 36
  • 58
-1

You can always try the method tryFindingViewWithAccessibilityLabel:error: which returns true if it can find it and false otherwise.

if ([tester tryFindingViewWithAccessibilityLabel(@"login") error: nil]){
    //Test things
}
Parsa T
  • 411
  • 3
  • 9