Projects:Upgrade to JUnit 4.11/Technical Specification
Contents |
Introduction
This project is basically going to upgrade the JUnit libraries to the latest stable version 4.11. This project will cover the refactor of all the test cases to make them use the new notation
For these changes, there are two possible ways to do future test cases :
- a) by using latest stable version 4.11. with new notations.
- It is recommended to use the 4.11 version because it has a lot of improvements: specific notation, hamcrest,...In this new version it's important that know what class is OBBaseTest.java. OBBaseTest class which can/should be extended by most other test classes which want to make use of the Openbravo test infrastructure.
- b) by using previous version. This version was deprecated.
- If it is necessary to continue using the deprecated version, "BaseTest" still using the previous notation (Version 3x).
Technical Considerations
JUnit 3x Vs JUnit 4.11
It is recommended to use the 4.11 version because it has a lot of improvements. For example:
- All test methods are annotated with @Test. Unlike JUnit3 tests, you do not need to prefix the method name with "test" (and usually don't).
- Do not have your test classes extend junit.framework.TestCase (directly or indirectly). Usually, tests with JUnit4 do not need to extend anything (which is good, since Java does not support multiple inheritance).
- Do not use any classes in junit.framework or junit.extensions.a) would result in a criteria like this {fieldName: columnName$_identifier, operation: 'equals', value:...}, and b would result in something like: {fieldName: columnName$_identifier, operation: 'iContains', value:...}.
- We can see a summary table:
Features | JUnit 3.x | Junit 4.x |
---|---|---|
Test annotation | test* pattern | @Test |
Run at the beginning | --- | @BeforeClass |
Run at the end | --- | @AfterClass |
Run before each test method | override setUp() | @Before |
Run after each test method | override tearDown() | @After |
Ignore test | change name method, ... | @Ignore |
Run at the end | --- | @AfterClass |
Timeouts | --- | @Test(timeout = 1000) |
Exceptions | Catch exceptions | @Test(expected =Exception.class) |
- You can search all information about JUnit 4.11 in JUnit Wiki: https://github.com/junit-team/junit/wiki
Location of test cases
It have been change the location of the test. Now test case are in different project called OpenbravoTest. There are some changes to explain:
- Now one new project need to be imported in the workspace (by menu File=>Import and then General=>Existing Projects into Workspace). Here they are:
OpenbravoTest XXX\opensource\openbravo\erp\devel\main\src-test
- Now, compilation of tests is done separately.
- All - jars need to be included in lib/test directory instead of lib directory for create a test case.