WOLFRAM

Enable JavaScript to interact with content and submit forms on Wolfram websites. Learn how
Wolfram Language & System Documentation Center

TestCreate [input]

create a TestObject to determine whether input evaluates to True .

TestCreate [input,expected]

create a TestObject to determine whether input evaluates to expected.

TestCreate [input,expected,messages]

create a TestObject that is expected to generate the list of message names messages.

Details and Options
Details and Options Details and Options
Examples  
Basic Examples  
Scope  
Basic Uses  
Options  
MemoryConstraint  
SameTest  
TestID  
TimeConstraint  
MetaInformation  
Possible Issues  
See Also
Tech Notes
Related Guides
Related Workflows
Related Links
History
Cite this Page

TestCreate [input]

create a TestObject to determine whether input evaluates to True .

TestCreate [input,expected]

create a TestObject to determine whether input evaluates to expected.

TestCreate [input,expected,messages]

create a TestObject that is expected to generate the list of message names messages.

Details and Options

Examples

open all close all

Basic Examples  (4)

Create a test that tests whether the input evaluates to True :

Wolfram Language code: test = TestCreate[Sin[E] > Cos[E]]

Evaluate the test:

Wolfram Language code: TestEvaluate[test]

Test whether the input evaluates to the expected output:

Wolfram Language code: TestEvaluate[TestCreate[Expand[(1 + x) ^ 3], 1 + 3 x + 3 x^2 + x^3]]

When a test fails, it returns an outcome of Failure:

Wolfram Language code: TestEvaluate[TestCreate[2 + 2, 3]]

When the input evaluates to the expected output but gives messages, the outcome is MessagesFailure:

Wolfram Language code: TestEvaluate[TestCreate[(1/0), ComplexInfinity]]

Add the expected message:

Wolfram Language code: TestEvaluate[TestCreate[1 / 0, ComplexInfinity, {Power::infy}]]

Scope  (2)

Basic Uses  (2)

Perform a test and present the results in a Dataset :

Wolfram Language code: test = TestEvaluate[TestCreate[1 / 0, ComplexInfinity]]; Dataset[test[All]]

Test if the results of an NIntegrate are numerically equivalent to Integrate by using an absolute tolerance:

Wolfram Language code: NIntegrate[Sin[x], {x, 0, 2}] - Integrate[Sin[x], {x, 0, 2}]
Wolfram Language code: TestEvaluate[TestCreate[ Abs[NIntegrate[Sin[x], {x, 0, 2}] - Integrate[Sin[x], {x, 0, 2}]] < 10^-14, True ]]

This can also be done by using the SameTest option:

Wolfram Language code: test = TestCreate[ NIntegrate[Sin[x], {x, 0, 2}], Integrate[Sin[x], {x, 0, 2}], SameTest -> (Abs[#1 - #2] ≤ 10^-14&) ];
Wolfram Language code: TestEvaluate[test]

Options  (13)

MemoryConstraint  (1)

Run a test until a memory limit is exceeded:

Wolfram Language code: ByteCount[RandomImage[]]
Wolfram Language code: test = TestCreate[ Head @ RandomImage[], Image, MemoryConstraint -> Quantity[80, "Kilobytes"] ];
Wolfram Language code: TestEvaluate[test]["ActualOutput"]

SameTest  (5)

Test whether the input is an integer:

Wolfram Language code: test = TestCreate[ RandomInteger[{1, 10}], _Integer, SameTest -> MatchQ ];
Wolfram Language code: TestEvaluate[test]

Test if the absolute precision of the input is at least 10-12:

Wolfram Language code: test = TestCreate[ 1., 1. + 5 10.^-13, SameTest -> (Abs[#1 - #2] ≤ 10^-12&) ];
Wolfram Language code: TestEvaluate[test]

Test if the relative precision is at least 10-5:

Wolfram Language code: test = TestCreate[ 1., 1.0001, SameTest -> (Abs[(#1 - #2) / #2] ≤ 10^-5&) ];
Wolfram Language code: TestEvaluate[test]

Test if two expressions are equivalent after simplification:

Wolfram Language code: test = TestCreate[ Cos[x]^2 + Sin[x]^2, 1, SameTest -> (Simplify[#1] === Simplify[#2]&) ]; TestEvaluate[test]

Use Unevaluated to pass unevaluated expressions to the SameTest function:

Wolfram Language code: test = TestCreate[Unevaluated[RandomReal[]], Unevaluated[RandomReal[]]];
Wolfram Language code: TestEvaluate[test]

You can use a combination of Function and Echo to print the arguments of the SameTest function:

Wolfram Language code: test = TestCreate[ StringJoin[2], Unevaluated[StringJoin[2]], {StringJoin::string}, SameTest -> Function[ {left, right}, SameQ @@Echo[HoldComplete[left, right]], HoldAllComplete ] ];
Wolfram Language code: TestEvaluate[test]

TestID  (4)

Add a TestID to the test:

Wolfram Language code: TestCreate[1 + 1, 2, TestID -> "myTestID"]

A TestID can be any expression:

Wolfram Language code: Table[ TestCreate[n + 2 > 0, True, TestID -> {"NumericTest", n}], {n, 3} ]

By default, the TestID is a Hash of the test:

Wolfram Language code: VerificationTest[2 + 2, 4]["TestID"]

The TestID will change if the input of the TestCreate expression is different:

Wolfram Language code: VerificationTest[2 + 2, 5]["TestID"]

Use CreateUUID to create random identifiers every time:

Wolfram Language code: TestCreate[2 + 2, 5, TestID :> CreateUUID[]]["TestID"]

TimeConstraint  (1)

Terminate the test if it takes more than one second:

Wolfram Language code: test = TestCreate[Pause[2], Null, TimeConstraint -> Quantity[1, "Seconds"]];
Wolfram Language code: TestEvaluate[test]["ActualOutput"]

MetaInformation  (2)

Store arbitrary metainformation in the TestObject :

Wolfram Language code: test = TestCreate[ 1, 2 + 2, MetaInformation -> <|"$MachineID" -> $MachineID|> ]

Access the stored MetaInformation :

Wolfram Language code: test["MetaInformation"]

MetaInformation can be any expression:

Wolfram Language code: test = TestCreate[2 + 2, 4, MetaInformation -> {$MachineID, $KernelID}]
Wolfram Language code: test["MetaInformation"]

Possible Issues  (3)

The expected output is evaluated before comparison with the actual output:

Wolfram Language code: test = TestCreate[RandomReal[], RandomReal[]];
Wolfram Language code: TestEvaluate[test]

Use Unevaluated to compare expressions before evaluation happens:

Wolfram Language code: test = TestCreate[Unevaluated[RandomReal[]], Unevaluated[RandomReal[]]];
Wolfram Language code: TestEvaluate[test]

Messages generated on evaluation of expected output are not accounted for in the expected messages:

Wolfram Language code: TestEvaluate[TestCreate[ComplexInfinity, 1 / 0]]

If SameTest does not evaluate to True or False , a failure type of "SameTestUnevaluated" is reported:

Wolfram Language code: Equal[x, y]
Wolfram Language code: TestEvaluate[TestCreate[x, y, SameTest -> Equal]]

Related Workflows

Wolfram Research (2023), TestCreate, Wolfram Language function, https://reference.wolfram.com/language/ref/TestCreate.html.

Text

Wolfram Research (2023), TestCreate, Wolfram Language function, https://reference.wolfram.com/language/ref/TestCreate.html.

CMS

Wolfram Language. 2023. "TestCreate." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/TestCreate.html.

APA

Wolfram Language. (2023). TestCreate. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/TestCreate.html

BibTeX

@misc{reference.wolfram_2026_testcreate, author="Wolfram Research", title="{TestCreate}", year="2023", howpublished="\url{https://reference.wolfram.com/language/ref/TestCreate.html}", note=[Accessed: 14-August-2026]}

BibLaTeX

@online{reference.wolfram_2026_testcreate, organization={Wolfram Research}, title={TestCreate}, year={2023}, url={https://reference.wolfram.com/language/ref/TestCreate.html}, note=[Accessed: 14-August-2026]}

Top [フレーム]

AltStyle によって変換されたページ (->オリジナル) /