iosswiftobjective-cxctestxcuitest

Can XCTestCases be grouped hierarchically?


I'm looking for a way (if it's even possible) to hierarchically group my XCTestCases. I've been googling and the only somewhat similar thing I found is Grouping Tests into Substeps with Activities, which is not what I want (grouping individual tests and groups into other groups).

For example, here's what the thing I want to do looks like in other languages, e.g. Dart (but it's very similar with Jest in JavaScript land as well):

void main() {
  group('Top group', () {
    group('nested group 1', () {
      test('test case 1', () {});
      test('test case 2', () {});
      // ...
    });

    group('some other nested group', () { /* test cases here ... */ });
  });
}

The structure is detected by the tooling such as IDEs:

enter image description here

Is it possible to accomplish this with XCTestCase? Ideally the solution could be accomplished entirely at runtime, it could even involve some dark magic with Objective-C runtime, as long as it had a chance to work.

If it's not possible, I'd like to hear that as well. Thanks in advance!


Solution

  • With plain XCTest, no. But with the third-party library Quick, yes. https://github.com/Quick/Quick