JUnit concepts

    1  Test class architecture
       1.1  Test class declaration
       1.2  Test assertions
       1.3  Errors and fails
    2  Test cases execution
    3  See also

This article explains several key concepts about the JUnit framework, which is the Unit tests framework used by the J661 project.

Test class architecture

Test class declaration

A JUnit test is a class which name ends with the Test string (for example: MapsDependencyTest is a valid test class name), and with tests methods annotated with the @Test annotation.
For example for a very simple Test class which tests nothing:
      public class MyTest {
      public void aTestMethod {

Test assertions

Assertions are used to check if a result is consistent with an expected value. Some kinds of built−in JUnit assertions are:

Errors and fails

There is a difference between a Unit Test fail and an error:
For example this test case will result in an error:
      public void aTestMethod {
      int i = 1 / 0;
And this test case will result in a fail:
      public void aTestMethod {
      assertTrue("Value must be true", false);

Test cases execution

JUnit executes the test classes by: Note that beginning with Java 7, there is no way to control the order on which the test cases will be executed. There is however a way to control this order in J661 Unit tests.
Also the fact that there is an instanciation of the test class for each test case means that if you want to keep values and states between several test cases, you will need to set static fields for the class to be able to keep them between several test methods call. The affection of these values can for example be performed in the @BeforeClass method.

See Also

Category:junit Category:dev

Copyright 2016 Dassault Aviation. All Rights Reserved. Documentation and source under the GPL v2 licence

Project Web Hosted by SourceForge.net Copyright 1999-2010 - Geeknet, Inc., All Rights Reserved About - Legal - Help