All Projects → StyleShare → Testables

StyleShare / Testables

Licence: MIT license
Make private properties testable

Programming Languages

swift
15916 projects
ruby
36898 projects - #4 most used programming language

Projects that are alternatives of or similar to Testables

carina
Carina automation framework: Web, Mobile, API, DB etc testing...
Stars: ✭ 652 (+1530%)
Mutual labels:  test
unity-test-runner
Run tests for any Unity project
Stars: ✭ 134 (+235%)
Mutual labels:  test
framework
Lightweight, open source and magic-free framework for testing solidity smart contracts.
Stars: ✭ 36 (-10%)
Mutual labels:  test
biobakery workflows
bioBakery workflows is a collection of workflows and tasks for executing common microbial community analyses using standardized, validated tools and parameters.
Stars: ✭ 60 (+50%)
Mutual labels:  private
PixelTest
Fast, modern, simple iOS snapshot testing written purely in Swift.
Stars: ✭ 56 (+40%)
Mutual labels:  test
tead
Lighting the way to simpler testing
Stars: ✭ 55 (+37.5%)
Mutual labels:  test
phpunit-injector
Injects services from a PSR-11 dependency injection container to PHPUnit test cases
Stars: ✭ 62 (+55%)
Mutual labels:  test
patchgirl
Manual reproducible web API tests for web developers
Stars: ✭ 95 (+137.5%)
Mutual labels:  test
goreporter
A Golang tool that does static analysis, unit testing, code review and generate code quality report.
Stars: ✭ 3,019 (+7447.5%)
Mutual labels:  test
ara
Agile Regression Analyzer
Stars: ✭ 74 (+85%)
Mutual labels:  test
vue-testing-with-jest-conf17
Examples on how to test Vue with Jest, based on the presentation at VueConf17
Stars: ✭ 37 (-7.5%)
Mutual labels:  test
shellmetrics
Cyclomatic Complexity Analyzer for bash, mksh, zsh and POSIX shells
Stars: ✭ 36 (-10%)
Mutual labels:  test
threat9-test-bed
No description or website provided.
Stars: ✭ 26 (-35%)
Mutual labels:  test
mutode
Mutation testing for JavaScript and Node.js
Stars: ✭ 61 (+52.5%)
Mutual labels:  test
very good performance
Utility on top of the Flutter Driver API that facilitates measuring the performance of your app in an automated way created by Very Good Ventures 🦄
Stars: ✭ 78 (+95%)
Mutual labels:  test
ngx-testbedder
CLI tool for writing the test bed for Angular integration test
Stars: ✭ 13 (-67.5%)
Mutual labels:  test
javascript-assertivo
Um guia fundamental e prático sobre qualidade de código e testes em todas as camadas de uma aplicação JavaScript.
Stars: ✭ 75 (+87.5%)
Mutual labels:  test
jest-expect-contain-deep
Assert deeply nested values in Jest
Stars: ✭ 68 (+70%)
Mutual labels:  test
scalatest-junit-runner
JUnit 5 runner for Scalatest
Stars: ✭ 30 (-25%)
Mutual labels:  test
playwright-test
Run unit tests with several runners or benchmark inside real browsers with playwright.
Stars: ✭ 81 (+102.5%)
Mutual labels:  test

Testables

CocoaPods CI

Make private properties testable.

Background

Let's assume that there is a class named ProfileViewController. This class has a property username which sets usernameLabel.text when the new value is assigned. Unfortunately, we cannot write an unit test because usernameLabel is a private property.

ProfileViewController.swift

class ProfileViewController {
  var username: String? {
    didSet {
      self.usernameLabel.text = self.username
    }
  }
  private let usernameLabel = UILabel()
}

ProfileViewControllerTests.swift

// when
viewController.username = "devxoul"

// then
let usernameLabel = viewController.usernameLabel // 🚫 private
XCTAssertEqual(usernameLabel.text, "devxoul")

Solution

Testables provides a generic way to expose private properties using Swift KeyPath.

Add the lines below to ProfileViewController.swift:

#if DEBUG
import Testables

extension ProfileViewController: Testable {
  final class TestableKeys: TestableKey<Self> {
    let usernameLabel = \Self.usernameLabel
  }
}
#endif

And update the test code:

// when
viewController.username = "devxoul"

// then
let usernameLabel = viewController.testables[\.usernameLabel] //
XCTAssertEqual(usernameLabel.text, "devxoul")

License

Testables is under MIT license. See the LICENSE file for more info.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].