Skip to content
This repository has been archived by the owner on Jan 10, 2023. It is now read-only.

Clean up "try" calls in tests #93

Open
vicng opened this issue May 4, 2016 · 0 comments
Open

Clean up "try" calls in tests #93

vicng opened this issue May 4, 2016 · 0 comments

Comments

@vicng
Copy link
Contributor

vicng commented May 4, 2016

All try! calls should be replaced with try.

The calls then need to be refactored according to the following rules:

  1. When we expect the method call to fail, wrap the try call inside a BKYAssertThrow.
func testMakeBlockError() {
  let blockFactory = BlockFactory()
  BKYAssertThrow(errorType: BlocklyError.self) {
     _ = try blockFactory.makeBlock(name: "some block that doesn't exist")
  }
}
  1. When we are specifically testing a method to succeed, wrap it inside a BKYAssertDoesNotThrow.
func testMakeBlockSuccess() {
  let blockFactory = BlockFactory()
  blockFactory.load(fromDefaultFiles: .colorDefault)
  let block = BKYAssertDoesNotThrow { try blockFactory.makeBlock(name: "colour_picker") }
  XCTAssertNotNil(block)
}
  1. For all other cases (ie. setup code), call the method normally and mark the test with throws.
func testWorkspaceAddBlock() throws {
  let workspace = Workspace()
  // Don't need to wrap this call since it's just setup code
  let block = try BlockBuilder(name: "test").makeBlock()

  // Wrap with BKYAssertDoesNotThrow() here since this is being tested.
  BKYAssertDoesNotThrow { try workspace.addBlockTree(block) }
}
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant