Sunday, December 16, 2018

XCUITesting : Using Assertions with Objective C and Swift

XCTest assertions that perform equality tests are divided between those that compare objects and those that compare nonobjects. For example, XCTAssertEqualObjects tests equality between two expressions that resolve to an object type while XCTAssertEqual tests equality between two expressions that resolve to the value of a scalar type.

This difference is marked in the XCTest assertions listing by including “this test is for scalars” in the description. Marking assertions with “scalar” this way informs you of the basic distinction, but it is not an exact description of which expression types are compatible.

For objective C, assertions marked for Scalar types can be used with the equality comparison operators: ==, !=, <=, <, >= and >. IF the expression resolves to any C type, struct or array comparison that works with these operators, it is considered as scalar.

For swift, assertions marked for scalar can be used to compare any expression type that conforms to the Equatable protocol ( for all of the "equal" or "not equal" assertions) and Comparable protocol for "greater than" or "less than"  assertions. In addition, assertions marked for scalars have overrides for (T) and for (K:V), where T, K and V conform to Equatable or Comparable protocols. For e.g. arrays of an equatable type are compatible with XCAssertEqual(_:_:_:file:line:), and dictionaries whose keys and values are both comparable types are compatible with XCAssertTypeLessThan(_:__:file:line:).

Using XCTest assertions in our test also differs between Objective-C and Swift because of how language differ in treating data types and implicit conversions.

For Objective-C, the use of implicit conversions in the XCTest implementation allows the comparisons to operate independent of the expressions’ data types, and no check is made of the input data types.

For Swift, implicit conversions are not allowed because Swift is stricter about type safety; both parameters to a comparison must be of the same type. Type mismatches are flagged at compile time and in the source editor.

references:
https://developer.apple.com/library/archive/documentation/DeveloperTools/Conceptual/testing_with_xcode/chapters/04-writing_tests.html#//apple_ref/doc/uid/TP40014132-CH4-DontLinkElementID_5

1 comment:

  1. -- Living Mobile --: Xcuitesting : Using Assertions With Objective C And Swift >>>>> Download Now

    >>>>> Download Full

    -- Living Mobile --: Xcuitesting : Using Assertions With Objective C And Swift >>>>> Download LINK

    >>>>> Download Now

    -- Living Mobile --: Xcuitesting : Using Assertions With Objective C And Swift >>>>> Download Full

    >>>>> Download LINK wS

    ReplyDelete