Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision |
student:junit:v3 [2018/08/14 13:28] – bernstdh | student:junit:v3 [2018/08/14 13:33] (current) – bernstdh |
---|
and must include a class declaration of the following form: | and must include a class declaration of the following form: |
| |
''public class //ClassName//Test extends TestCase ''+ | |
| | public class //ClassName//Test extends TestCase | |
| |
So, continuing with the example above, ''%%AtomTest.java%%'' would initially contain the following: | So, continuing with the example above, ''%%AtomTest.java%%'' would initially contain the following: |
In the "setup" portion, this method creates an ''%%Atom%%'' objects (for oxygen). It then calls the ''%%Assert.assertEquals()%%'' method to tell jUnit to do some testing. This particular version of the ''%%Assert.assertEquals()%%'' method is passed three parameters and has the following syntax: | In the "setup" portion, this method creates an ''%%Atom%%'' objects (for oxygen). It then calls the ''%%Assert.assertEquals()%%'' method to tell jUnit to do some testing. This particular version of the ''%%Assert.assertEquals()%%'' method is passed three parameters and has the following syntax: |
| |
| Assert.assertEquals(//Description//, //ExpectedValue//, //ActualValue//); | | |
| |
| | Assert.assertEquals(//Description//, //ExpectedValue//, //ActualValue//); | |
| |
The //Description// is a human-readable ''%%String%%'' that provides information that enables the tester to understand the test in the event that the code fails the test. The //ExpectedValue// contains the correct value (i.e., the value that the tester expects if the method named //MethodName// in //ClassName// is working correctly. The //ActualValue// contains the value that was actually generated by the method named //MethodName// in //ClassName//. | The //Description// is a human-readable ''%%String%%'' that provides information that enables the tester to understand the test in the event that the code fails the test. The //ExpectedValue// contains the correct value (i.e., the value that the tester expects if the method named //MethodName// in //ClassName// is working correctly. The //ActualValue// contains the value that was actually generated by the method named //MethodName// in //ClassName//. |
| |
When using ''%%Assert.assertEquals()%%'' to compare floating point numbers (e.g., ''%%double%%'' values), one must be careful. In general, one should not use the ''%%==%%'' operator with ''%%double%%'' values because of the less-than-perfect precision of operations on ''%%double%%'' values. In JUnit, the implication of this is that one should check to see if ''%%double%%'' values are within a tolerance value of each other. Hence, when comparing ''%%double%%'' values one should use the following: | When using ''%%Assert.assertEquals()%%'' to compare floating point numbers (e.g., ''%%double%%'' values), one must be careful. In general, one should not use the ''%%==%%'' operator with ''%%double%%'' values because of the less-than-perfect precision of operations on ''%%double%%'' values. In JUnit, the implication of this is that one should check to see if ''%%double%%'' values are within a tolerance value of each other. Hence, when comparing ''%%double%%'' values one should use the following: |
| |
| Assert.assertEquals(//Description//, //ExpectedValue//, //ActualValue//, //tolerance//); | | |
| | Assert.assertEquals(//Description//, //ExpectedValue//, //ActualValue//, //tolerance//); | |
| |
| |
| |