title: How to use XCTestSuite? (Swift 3)
body: <p>We have a Jenkins job that runs our iOS UI tests, and I need to be able to ignore some tests (or test classes) based on certain runtime information during a test run. According to the XCTestSuite documentation <a href="https://developer.apple.com/reference/xctest/xctestsuite" rel="nofollow noreferrer">https://developer.apple.com/reference/xctest/xctestsuite</a> you can create a custom test suite programmatically, but I haven't found any examples of how to actually do so. So how exactly does one go about it?</p>
  
  <p>I've toyed with this with the code below as a starting point, but haven't really gotten anywhere. When the IgnoreThisClass is run in Xcode, the test method in it gets run even though the testCaseCount in BaseTestClass' setUp()  reports 0 tests in suite. Do I need to override some init() method instead or do something else? Any tips would be greatly appreciated!</p>
  
  <pre><code>import XCTest
  
  class BaseTestClass: XCTestCase {
      var runThis: Bool?
  
      override func setUp() {
          if runThis != nil {
              let suite = XCTestSuite(name: "Custom suite")
  
              if runThis! {
                  suite.addTest(self)
              }
              print("Testcases in suite \(suite.testCaseCount)")
              // This causes an error that the suite has already started,
              // even though this call is present in Apple's example documentation.
              //suite.run()
          }
          XCUIApplication().launch()
      }
  
      override func tearDown() {
         super.tearDown()
      }
  }
  
  // Run this.
  class RunThisClass: BaseTestClass {
  
      override func setUp() {
          super.runThis = true
          super.setUp()
      }
  
      override func tearDown() {
          super.tearDown()
      }
  
      func testThis() {
          print("Test class was run.")
      }
  }
  
  // Don't run this.
  class IgnoreThisClass: BaseTestClass {
  
      override func setUp() {
          super.runThis = false
          super.setUp()
      }
  
      override func tearDown() {
          super.tearDown()
      }
  
      func testIgnoreThis() {
          print("Ignored class was run.")
      }
  }
  </code></pre>