How to run one-time setup code before executing any XCTest

前端 未结 4 734
感情败类
感情败类 2020-12-28 12:52

I have the following problem. I want to execute a piece of code before all test classes are executed. For instance: I don\'t want my game to use the SoundEngine singleton du

4条回答
  •  囚心锁ツ
    2020-12-28 13:14

    If you build a superclass for your test case to be based on, then you can run a universal setup in the superclass and do whatever specific setup you might need to in the subclasses. I'm more familiar with Obj-C than Swift and haven't had a chance to test this yet, but this should be close.

    // superclass
    class SuperClass : XCTestCase {        
        override func setUp() {
            SilentSoundEngine.activate () // SoundEngine is a singleton
        }
    }
    
    // subclass
    class Subclass : Superclass {
        override func setUp() {
            super.setup()
        }
    }
    

提交回复
热议问题