Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable assertions while testing

I want to test the contract of my API so if, for example, an object is created with some parameter to nil an assertion is raised, but if the assertions are disabled (Release config) it simply returns nil.

My test scheme has the build configuration to Debug, so in my API contract tests I check if the creation of an object with some parameters to nil returns a nil object. But the assertion of the constructor is raised before the XCTAssertNil is executed, so my test always fails.

Can I disable the assertions while testing? I tried to add NS_BLOCK_ASSERTIONS to the scheme arguments passed on launch but that doesn't work.

like image 740
emenegro Avatar asked May 06 '15 14:05

emenegro


People also ask

How do I turn off assertions?

You must #define NDEBUG (or use the flag -DNDEBUG with g++) this will disable assert as long as it's defined before the inclusion of the assert header file.

How do I disable assert in java?

To configure assertion options one must use either the -ea or -da command line flags to enable or disable assertions with the command line tool: “java”. For example, “java -ea Assert” where Assert is a java class file.

How do I turn off assert in Python?

Using the -O flag (capital O) disables all assert statements in a process.

Can a test case have multiple assertions?

you can have multiple asserts on the same object. they will usually be the same concept being tested.


1 Answers

Solved, I added a new configuration, duplicated from Debug, called Test.

enter image description here

Then added NS_BLOCK_ASSERTIONS=1 in the build settings preprocessor macros.

enter image description here

Finally, change the test action in the test's scheme.

enter image description here

Now it works :)

like image 73
emenegro Avatar answered Oct 03 '22 11:10

emenegro