主要内容

Table of Verifications, Assertions, and Other Qualifications

There are four types of qualifications for testing values and responding to failures: verifications, assumptions, assertions, and fatal assertions.

  • Verifications — Produce and record failures without throwing an exception, meaning the remaining tests run to completion.

  • 假设 - 仅当满足某些先决条件并且事件不应产生测试故障时,确保测试才能运行。当发生假设失败时,测试框架将测试标记为过滤。

  • Assertions — Ensure that the preconditions of the current test are met.

  • Fatal assertions — Use this qualification when the failure at the assertion point renders the remainder of the current test method invalid or the state is unrecoverable.

测试类型 Verification Assumption Assertion Fatal Assertion
Value is true. 验证 假设 assertTrue fatalAssertTrue
Value is false. verifyFalse assumeFalse astfalse fatalAssertFalse
值等于指定值。 verifyEqual assumeEqual assertEqual fatalAssertEqual
Value is not equal to specified value. verifyNotEqual assumeNotEqual assertNotEqual FatalAssertnotequal
Two values are handles to same instance. verifySameHandle assumeSameHandle assertSameHandle fatalAssertSameHandle
Value is not handle to specified instance. verifyNotSameHandle assumeNotSameHandle assertNotSameHandle fatalAssertNotSameHandle
Function returns true when evaluated. verifyReturnsTrue assumeReturnsTrue Assertreturnstrue fatalassertretertnstrue
Test produces unconditional failure. verifyFail assumeFail assertFail Fatalassertfail
Value meets given constraint. 验证 假使,假设 assertThat fatalAssertThat
Value is greater than specified value. verifyGreaterThan assumeGreaterThan Assertgreaterthan fatalAssertGreaterThan
值大于或等于指定值。 verifygreaterthanorequal assumeGreaterThanOrEqual AssertgreaterthanOrEqual Fatalassertgreaterthanorequal
Value is less than specified value. verifyLessThan assumeLessThan assertLessThan fatalAssertLessThan
Value is less than or equal to specified value. verifyLessThanOrEqual 毫无疑问 assertLessThanOrEqual fatalAssertLessThanOrEqual
Value is exact specified class. verifyClass assumeClass assertClass fatalAssertClass
Value is object of specified type. verifyInstanceOf assumeInstanceOf assertInstanceOf fatalAssertInstanceOf
Value is empty. verifyEmpty assumeEmpty assertEmpty fatalAssertEmpty
Value is not empty. verifyNotEmpty assumeNotEmpty assertNotEmpty fatalAssertNotEmpty
Value has specified size. verifySize assumeSize assertSize fatalAssertSize
Value has specified length. verifyLength assumeLength assertLength fatalAssertLength
Value has specified element count. verifyNumElements assumeNumElements assertNumElements fatalAssertNumElements
String contains specified string. verifySubstring assumeSubstring assertSubstring fatalAssertSubstring
Text matches specified regular expression. verifyMatches 假设 assertMatches fatalAssertMatches
Function throws specified exception. verifyError assumeError assertError Fatalasserterror
功能问题指定警告。 verifyWarning assumeWarning 主张 fatalAssertWarning
Function issues no warnings. verifyWarningFree 假设免费 主张Free fatalAssertWarningFree

See Also

||||