Language:EN
Pages: 5
Rating : ⭐⭐⭐⭐⭐
Price: $10.99
Page 1 Preview
here the command run the gui java junit com figure

Here the command run the gui java junit com figure

A test failure occurs when an assertXXX( ) statement fails. A test error occurs when a unit test throws an exception.

After fixing the Person class, we can run the tests again. We see the following output: java junit.textui.TestRunner
com.oreilly.javaxp.junit.TestPerson
..

Figure 4-2 shows the Test Hierarchy tab. This tab allows you to see which of the unit tests passed or failed, and allows you to re-run individual tests.

Figure 4-2. Test Hierarchy tab

4.3.3.3 Reload classes every run
On a final note, the JUnit GUI provides a checkbox allowing you to "Reload classes every run." When checked, the JUnit ClassLoader reads the latest .class files for your tests each time they are run.

This allows you to leave the GUI up while you recompile your source code. The new classes are loaded the next time you click the Run button.

Table 4-1 summarizes the various assertXXX( ) methods that can be found in
junit.framework.Assert. Although you could get by with using assertTrue( ) for nearly every test, using one of the more specific assertXXX( ) methods often makes your tests more understandable and provides good failure messages. This table is only a summary; each of the methods is overloaded as described shortly.

Table 4-1. Assert method summary
Method Description

assert( )

assertFalse( ) Evaluates a boolean expression. The test passes if the expression is false.

Compares an object reference to null. The test passes if the reference is not null.

assertNotSame( )

Compares the memory address of two object references using the == operator. The test passes if both refer to the same object.

assertTrue( )

All of the methods in Table 4-1 are overloaded to accept an optional String as the first argument. When specified, this argument provides a descriptive message should the test fail. Here is an example that shows two assert statements, one with the description and one without:

assertEquals(employeeA, employeeB);
assertEquals("Employees should be equal after the clone( ) operation.",
employeeA, employeeB);

assertSame("Expected the two parts to be identical.", part1, part2);
assertTrue("Expected the two parts to be identical.", part1 == part2);

While assertSame( ) compares memory addresses, assertEquals( ) compares contents. For objects, this means the .equals( ) method is used instead of ==.

assertEquals("Temperature", expectedTemp, actualTemp, 0.001);

4.4.3.3 Additional examples

JUnit 3.8 added the assertFalse( ) method, making the test more clear:

assertFalse("The car should not be running.", car.isRunning( ));

You are viewing 1/3rd of the document.Purchase the document to get full access instantly

Immediately available after payment
Both online and downloadable
No strings attached
How It Works
Login account
Login Your Account
Place in cart
Add to Cart
send in the money
Make payment
Document download
Download File
img

Uploaded by : Joan Evans

PageId: DOCD424805