1. Why testing?
A majority of the production failures (77%) can be reproduced by a unit test.
1.1. To deliver the good product
1.2. If it works for 1 doesn’t necessarily for 100
1.3. Murphy's law
Everything that can go wrong will eventually go wrong.
1.4. Different OS or different terms
1.5. To give the best
2. A concrete example of mandatory test
-
Fork the repository.
-
Run
bundleto install development dependencies. -
Create a topic branch
-
Add tests for your unimplemented feature or bug fix. (See [writing-and-executing-tests])
-
Run
bundle exec raketo run the tests. If your tests pass, return to step 4. -
Implement your feature or bug fix.
-
Run
bundle exec raketo run the tests. If your tests fail, return to step 6. -
Add documentation for your feature or bug fix.
-
If your changes are not 100% documented, go back to step 8.
-
Add, commit, and push your changes.
-
Submit a pull request.
3. Concrete example of mandatory documentation
[…] an Eclipse project is providing extensible frameworks and applications accessible via documented APIs.
4. Tests' Typology
|
Verification |
Validation |
|
Is the product good? |
Is it the good product? |
|
Are you building it right? |
Are you building the right thing? |
|
Mostly done by developers |
Mostly done by client |
|
Comes first |
After verification most of the time |
5. JUnit etc.
5.1. What to test?
|
Exceptions |
|
|
Execution time |
|
|
Specific environment |
|
5.2. Assertions
|
|
Force the test to fail |
|
|
Condition is true |
|
|
Condition is false |
|
|
Two values are equal |
|
|
null object |
|
|
identical objects (same réf.) |
5.3. Tests Strategies
Considering int add(int,int); from class myClass.
//for normal addition
@Test
public void testAdd1Plus1() {
int x = 1 ; int y = 1;
assertEquals(2, myClass.add(x,y));
}
Examples:
-
overflow
-
nullparameters -
negative parameters
-
…
//if you are using 0 as default for null, make sure your class works in that case.
@Test
public void testAdd1Plus1() {
int y = 1;
assertEquals(0, myClass.add(null,y));
}
5.4. Tests order
None!!
JUnit assumes that all test methods can be executed in an arbitrary order. Well-written test code should not assume any order, i.e., tests should not depend on other tests.
5.5. What about graphical interfaces?
Example of the Robot library:
Robot bot = new Robot();
bot.mouseMove(10,10);
bot.mousePress(InputEvent.BUTTON1_MASK);
//add time between press and release or the input event system may
//not think it is a click
try{Thread.sleep(250);}catch(InterruptedException e){}
bot.mouseRelease(InputEvent.BUTTON1_MASK);
Example of the swingcoder Eclipse plugin:
5.6. Tests' coverage
6. Concrete application
6.1. From To Be Done to On going
|
|
|
6.2. Create a specific branch (if new feature)
bruel (master) $ git checkout -b US-15378
Switched to a new branch 'US-15378'
bruel (US-15378) $
6.3. Write a failing test, then make it pass
6.4. Merge and do integration testing
bruel (US-15378) $ git commit -am "Adding push feature. Tests OK"
[US-15378 78f3242] Adding push feature. Tests OK
1 file changed, 2 insertions(+), 3 deletions(-)
bruel (US-15378) $ git checkout devs
Switched to branch 'devs'
bruel (devs) $ git merge US-15378
6.5. Commit & Push in devs
bruel (devs) $ git commit -am "..."
...
bruel (devs) $ git push origin devs
...
bruel (devs) $ git branch -D US-15378
Deleted branch US-15378 (was f392a73).
6.6. From On going to Review

