-
-
Notifications
You must be signed in to change notification settings - Fork 78
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unit testing #716
Unit testing #716
Changes from 6 commits
51d1b90
daf66b3
0e58ecd
23490ff
33b86f3
1bc47e3
a1b1c08
5b47d5c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# Testing in Wildbook | ||
|
||
## JUnit for Unit Testing | ||
|
||
Wildbook uses [JUnit 5](https://junit.org/junit5/docs/current/user-guide/) for unit testing. All unit tests _must run and pass_ in order for changes to be | ||
incorporated into the Wildbook codebase. Tests should be run automatically with maven when executing `mvn clean install`. | ||
|
||
**All new code** should have appropriate unit tests written to validate all components of the new code are working as expected. Take care to also test | ||
invalid data cases and failure/exception cases. | ||
|
||
Tests should be created under the `src/test/java/org/ecocean/` directories, corresponding to the java class which are testing. The test class name should follow | ||
the convention of adding the suffix `Test` to the java class name, such as `AnnotationTest.java` for tests of code within `Annotation.java`. | ||
|
||
Ultimately, almost all Wildbook java classes will have a corresponding `*Test.java` class. If one does not exist to add new tests to, it should be created | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
"That being said, edits to existing classes may not require full understanding of a class, while testing does. If you choose not to make a unit test for an existing class, make a note of that choice in the PR and explain why." |
||
using the above naming convention. | ||
|
||
There are many tutorials and guides to using JUnit online, such as [this one](https://www.vogella.com/tutorials/JUnit/article.html). | ||
|
||
### Running tests without compiling | ||
|
||
To test only specific test classes/methods, you can use the following with maven: | ||
|
||
``` | ||
mvn test # run all tests but no compiling | ||
|
||
mvn test -Dtest=TestClass1,TestClass2 # only these two classes | ||
|
||
mvn test -Dtest=TestClass#method # test a specific method | ||
``` | ||
|
||
|
||
## Integration Testing, Frontend Testing | ||
|
||
TBD / linked elsewhere | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TODO |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package org.ecocean; | ||
|
||
import org.ecocean.Annotation; | ||
import org.ecocean.media.*; | ||
import org.json.JSONObject; | ||
import org.junit.jupiter.api.Test; | ||
import static org.junit.Assert.*; | ||
|
||
class AnnotationTest { | ||
/* | ||
to create a (real) MediaAsset or a Feature we need to have a Shepherd! | ||
TODO extend to this with mockito/Shepherd | ||
https://semaphoreci.com/community/tutorials/stubbing-and-mocking-with-mockito-2-and-junit | ||
*/ | ||
@Test void createAnnotation() { | ||
AssetStore store = null; // see note above | ||
MediaAsset ma = new MediaAsset(store, null); | ||
Annotation ann = new Annotation("species", ma); | ||
|
||
assertNotNull(ann); | ||
assertTrue(ann.isTrivial()); | ||
assertEquals(ann.getMediaAsset(), ma); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for backend unit testing