-
-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #716 from WildMeOrg/unit_test_init
Unit testing
- Loading branch information
Showing
3 changed files
with
86 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# Testing in Wildbook | ||
|
||
## JUnit for Unit Testing | ||
|
||
Wildbook uses [JUnit 5](https://junit.org/junit5/docs/current/user-guide/) for backend 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`. | ||
|
||
Eventually, 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 | ||
using the above naming convention. 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. | ||
|
||
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 | ||
|
||
TODO |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |