Quick: [Xcode 8] Testing-related Xcode extension ideas

Created on 14 Jun 2016  路  8Comments  路  Source: Quick/Quick

The following would be cool source editing extensions -- not only for Quick, but for XCTest (and other testing frameworks too!):

  • Add a test for a selected class, function, or method.
  • Jump from class/function/method to its test.
  • Jump from test to the class/function/method it's testing.
  • [Quick-only] Focus on example or example group, un-focusing all other examples.
  • [Quick-only] Un-focus all examples and example groups.
  • [Quick-only] Mark example or example group as pending.
  • [Quick-only] Disable example or example group (xdescribe, xit).
  • Convert a block of code into a series of tests: one test for each level of cyclomatic complexity. For example, the following code:
func myFunction(foo: Bool) -> Int {
    if(foo) {
        return 10
    } else {
        return 0
    }
}

Should turn into something like this on XCTest:

class MyFunctionTests: XCTestCase {
    func test_myFunction_whenFooIsTrue_<# code snippet #>() {
        <# code snippet #>
    }

    func test_myFunction_whenFooIsFalse_<# code snippet #>() {
        <# code snippet #>
    }
}

And the following with Quick:

class MyFunctionSpec: QuickSpec {
    describe("myFunction") {
        context("when foo is true") {
            it("<# code snippet #>") {
                <# code snippet #>
            }
        }

        context("when foo is false") {
            it("<# code snippet #>") {
                <# code snippet #>
            }
        }
    }
}

Any other ideas?

enhancement help wanted discussion feature

Most helpful comment

Another idea ;-)

  • Collapse/Fold all beforeEach, afterEach, and it, making it easier to scan for a particular test.

Example:

describe(@"MenuViewController", ^{
    __block MenuViewController *controller;

    beforeEach(^{ ... });

    describe(@"table view data source", ^{
        __block NSArray<NSString *> *dataSource;

        beforeEach(^{ ... });

        describe(@"-tableView:numberOfRowsInSection:", ^{
            it(@"returns the correct number of rows", ^{ ... });
        });

        describe(@"-tableView:cellForRowAtIndexPath:", ^{
            it(@"returns the correct cell", ^{ ... });
        });
    });
});

All 8 comments

Heck, I'd be happy just to get Quick to run all my tests reliably and update xCode's test navigator.

Does xCode 8 do anything to XCTest to make quick specs more dependable?

@wm-j-ray The best way to help in that department is to duplicate https://openradar.appspot.com/26028557. It's unlikely that Xcode 8 will help with test discovery -- we need to tell Apple this is an issue people care about.

I always have my test and implementation files side by side, so:

  • open test for class/method/function on the Assistant Editor.
  • open class/method/function for test on the Assistant Editor.

Oooh yeah. I love having implementation and test side by side. Great ideas!

Another idea ;-)

  • Collapse/Fold all beforeEach, afterEach, and it, making it easier to scan for a particular test.

Example:

describe(@"MenuViewController", ^{
    __block MenuViewController *controller;

    beforeEach(^{ ... });

    describe(@"table view data source", ^{
        __block NSArray<NSString *> *dataSource;

        beforeEach(^{ ... });

        describe(@"-tableView:numberOfRowsInSection:", ^{
            it(@"returns the correct number of rows", ^{ ... });
        });

        describe(@"-tableView:cellForRowAtIndexPath:", ^{
            it(@"returns the correct cell", ^{ ... });
        });
    });
});

I'm super excited to see some other folks discussing this idea :)

Last year I was maintaining and building some Xcode Plugins that provide some of this functionality for Objective-C projects, but it's clear we have our work cut out for us in the future to build this on top of XcodeKit.

Can we try to organize some of these ideas in terms of APIs or use cases that XcodeKit would be good to expose? We've already captured some of the fit, xit, which should be possible with XcodeKit now, but we would also need some sort of inter-workspace, navigation API that would allow navigating to a file with a given name.

It also sounds like @ornithocoder wants to be able to toggle folding levels at given lines in the editor.

I also have a notion that it would be great to be able to build our own refactoring tools (like the ability to rename a class, symbol, constant, or interactively change the method signature of a function), which would need to have a much richer API still.

Have I missed anything? I'm hopeful to bring up some of these things with staff at the Xcode Labs while I'm at WWDC this week.

[Quick-only] Focus on example or example group, un-focusing all other examples.

Unsure if anyone else has started in on any of this functionality, but I've started a project that builds an Xcode 8+ app extension that allows you to easily focus / unfocus tests. You can just place your cursor anywhere inside the closure for a test and it will focus it.

For example:

it("should do something interesting") { 
  | // cursor is here
}

Would become:

fit("should do something interesting") { 
  | // cursor is here
}

Closing this as part of issue cleanup.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

modocache picture modocache  路  7Comments

nandin-borjigin picture nandin-borjigin  路  6Comments

J-Rojas picture J-Rojas  路  4Comments

ivanruizscm picture ivanruizscm  路  7Comments

lilyball picture lilyball  路  4Comments