Repository for sharing unit tests for OOP course
There is clone.sh bash script available which clones skeleton and tests for a task. Usage: ./clone.sh {task} {dest} - creates {task} directory in {dest}
-
If you don't have the repo on your machine:
- Fork the repository on Github
- Clone your repository into your machine
- Add remote upstream
git remote add upstream https://github.com/mhorod/oop-unit-tests
-
Sync local repository with remote
- If you haven'
6B7E
t commited your changes:
- Switch to
mainby runninggit checkout main - Execute
git pull upstream mainto sync changes
- Switch to
- If you commited your changes rebase instead of merging:
git fetchgit rebase origin/main
- If you haven'
6B7E
t commited your changes:
-
Create branch for your changes and switch to it
git branch {branch_name}git checkout {branch_name}
-
Add your tests to directory
oop-unit-tests/satori/{task}/Don't create new directories there. -
Make sure your tests compile by executing
bash check.sh- note: you can build a single task by providing the task name as an argument, e.g.
bash check.sh A
- note: you can build a single task by providing the task name as an argument, e.g.
-
Commit your changes and push them
-
Go to your repository on Github and create a pull request
This is recommended style guide for writing tests. While not necessary, following it will be highly appreciated.
In single java project there can exist only one class of given name. In order to avoid name conflicts prefix your test class with name and surname., e.g. class JohnDoeTests {}
With JUnit you can group your tests in nested classes with RunWith(@Enclosed.class)
Example test with nested classes:
import org.junit.*;
import org.junit.experimental.runners.Enclosed;
import org.junit.runner.RunWith;
import static org.junit.Assert.*;
@RunWith(Enclosed.class)
public class ExampleTest
{
public static class ExampleGroupTest
{
@Test
public void example_test_method() {}
}
}Use snake_case for naming test methods and use names that convey expected behavior.
e.g. size is a bad name for a test while size_of_new_list_is_zero is better.
Try to make your tests concise and focused on single thing. Test behavior rather than interface. If you have many assertions consider splling the test into more functions.
Put files with unit tests in directory src/test/java/ in your solution project.
- In toolbar click between
BuildandRunicons Edit ConfigurationsAdd new configuration > JUnitJUnit > Add new run configuration- Select
Classto run single test file - Select
All in directoryand select directory to run all tests - Press
Runicon to run tests