Coder Social home page Coder Social logo

xctestmashup's Introduction

Swift Version Xcode Platform backend CI Badge

XCTest unit testing

  • Core Data: Improvement of Singleton pattern by creating testing static variable.

    struct PersistentStore {
        static var shared: PersistentStore
        static var testing: PersistentStore
    }
  • UserDefaults: Subclass to create mock

    class MockUserDefaults: UserDefaults {
    
    }
  • Networking Layer: Protocol + Mock class

    protocol DataServiceProtocol {
    
    }
    
    class MockService: DataServiceProtocol {
    
    }
  • Other features

    • Test plans
      • UnitTests.xctestplan: Unit tests only
      • FullTests.xctestplan: Unit tests + UI test
    • Code coverage

Xcode CLI

  1. Build generate Build products & .xctestrun manifest file
    xcodebuild build-for-testing -scheme XCTestMashup -destination 'platform=iOS Simulator,OS=16.4,name=iPhone 14'
    
  2. Test using the above generated files to create Result Bundle. (Need to enter path)
    xcodebuild test-without-building -xctestrun "ENTER_PATH_HERE_FOR_XCTESTRUN Xcode/DerivedData/XCTest_Mashup.xctestrun" -destination 'platform=iOS Simulator,OS=16.4,name=iPhone 14'
    
  3. Display JSON format of Result Bundle containing Build log, Test report, Code coverage report, Test attachments
    xcrun xcresulttool get --path ResultBundle.xcresult --format json
    

The above steps could be used as the main steps for CI

Other commands:

Build & Test

xcodebuild test -project XCTestMashup.xcodeproj -scheme XCTestMashup -destination 'platform=iOS Simulator,OS=16.4,name=iPhone 14'

Testing on Multiple Destinations

xcodebuild test -scheme XCTestMashup -destination 'platform=iOS Simulator,OS=16.4,name=iPhone 14' -destination 'platform=iOS Simulator,OS=16.4,name=iPad (10th generation)'

Produce Result Bundles

xcodebuild test -scheme XCTestMashup -resultBundlePath $PWD/testresult/ResultBundle.xcresult -destination 'platform=iOS Simulator,OS=16.4,name=iPhone 14'

Code Coverage Reports with xccov

xcrun xccov view --report ResultBundle.xcresult

xctestmashup's People

Contributors

hanjustin avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.