Cucumberish

repository·master·Indexed 43 days ago

https://github.com/ahmed-ali/cucumberish

A BDD (Behaviour Driven Development) test automation framework for iOS that allows developers to write human-readable tests in Gherkin syntax and implement them in Swift or Objective-C, integrating with XCTest and Xcode's Test Navigator.

Tokens
1.3K
Snippets
3
Records
8
Agent score
6%

What's inside Cucumberish

  1. Install Cucumberish manually or with Carthage

    master

    Cucumberish supports multiple installation methods depending on your project requirements:

    • Manual Installation: Separate instructions are available for Objective-C and Swift test targets.
    • Carthage: Separate instructions are available for Objective-C and Swift test targets.

    Refer to the official Cucumberish Wiki for the specific step-by-step guides for your chosen method and language.

  2. Set up Continuous Integration for Cucumberish

    master
    To ensure your application remains functional, it is highly recommended to implement a Continuous Integration (CI) process. You can use tools like Bots, Jenkins, or any other tool that utilizes xcodebuild. When using xcodebuild, refer to its manpage for specific instructions on how to use test destinations.
  3. Write a Gherkin feature file

    master

    Cucumberish uses Gherkin syntax to define tests. Create a .feature file in your features folder.

    Rules for Feature Files:

    • You can have only one Feature per file.
    • You can have multiple Scenario blocks within a single file.
    • Every step must start with one of the following keywords: Given, When, Then, And, or But.
    • Given steps should be used to define the app state or preconditions before the rest of the scenario executes.
    Feature: Example
    As someone who plans to automate the iOS project test cases, I will use Cucumberish.
    
    Scenario: First scenario
        Given I have a very cool app
        When I automate it with "Cucumberish"
        Then I will be more confident about the quality of the project and its releases
  4. Install Cucumberish via CocoaPods

    master

    To install Cucumberish using CocoaPods, add the following to your Podfile. Ensure you use use_frameworks! as Cucumberish requires it.

    Note: After adding the pod, you must follow the specific setup steps for either Objective-C or Swift as detailed in the project wiki.

    use_frameworks!
    target 'YourAppTestTarget' do
      pod 'Cucumberish'
    end
  5. Resolve disappearing test cases in Xcode Test Navigator

    master
    If you execute an individual scenario or feature from the Xcode test navigator, you may notice that the rest of the test cases disappear from the navigator. To restore them, you must run all tests by pressing CMD+U or by clicking the 'Tests' button in Xcode.
  6. Troubleshoot missing step implementations

    master

    If a scenario fails because a step is not implemented even though you have written the code, the regex in your step definition is likely failing to match the text in the .feature file.

    Common causes:

    • Incorrect regular expression syntax.
    • Unintended whitespace in either the feature file or the regex string.

    Debugging Tip: Set a breakpoint in Cucumberish/Core/Managers/CCIStepsManagers.m within the method findDefinitionForStep:amongDefinitions to inspect the matching process.

  7. Troubleshoot Xcode Test Navigator navigation issues

    master

    If clicking a failed test in the Xcode Test Navigator does not open the corresponding .feature file, it is usually due to one of two reasons:

    1. Runtime Crash: If your code causes a crash (e.g., an out-of-bounds array access), Xcode cannot point to a feature file. Check the Reports Navigator in Xcode and expand the failed test item to see detailed error information.
    2. Installation Error: If you installed manually, you may have missed one of the initial installation steps. If using CocoaPods, you may have missed the post-installation steps.
  8. Implement step definitions in Objective-C

    master

    Step implementations are written in your test target's code. In Objective-C, you register steps within the CucumberishInit function before calling -[Cucumberish beginExecution].

    Step definitions use regular expressions to match the text in your .feature files. Regex capturing groups are passed into the implementation block via the args array in the order they were captured.

    // Inside CucumberishInit
    
    // Simple text match
    Given(@"I have a very cool app", ^(NSArray<NSString *> *args, NSDictionary *userInfo) {
        // Implementation logic here
        NSLog(@"\"Given I have a very cool app\" step is implemented");
    });
    
    // Regex match with capturing groups
    When(@"^I automate it with \"(.*)\"$", ^(NSArray<NSString *> *args, NSDictionary *userInfo) {
        // args[0] contains the captured group
        NSLog(@"I am gonna automate my test cases with %@", args[0]);
    });
    
    Then(@"I will be more confident about the quality of the project and its releases", ^(NSArray<NSString *> *args, NSDictionary *userInfo) {
        NSLog(@"Implemented step for the sake of the example");
    });