Skip to content

Commit

Permalink
Updated the doc
Browse files Browse the repository at this point in the history
  • Loading branch information
michbarsinai committed Jan 7, 2016
1 parent 21a279f commit 1d7eadc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
8 changes: 8 additions & 0 deletions doc/theTestableCommand/TheTestableCommand.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
> This document was started as a result of [Issue #2746 - Improve automated testing](https://github.com/IQSS/dataverse/issues/2746),
> started by @pdurbin.
* _2016-01-07_ `v3` More tips.
* _2016-01-07_ `v2` Added references to CI and code coverage. Limited scope to `DvObject`s.
* _2016-01-03_ `v1` Initial Version

Expand Down Expand Up @@ -107,6 +108,13 @@ Numerous blogs, books and tweets have been written about creating good unit test
<element attB="b" attA="a"/>
````

* The notion of *now* is an issue. Assume that a test needs to validate that the `creationTime` field on some `DvObject` is set to the time it is created. The naïve approach would be storing the time just before the execution of the `Create` command, and then testing that the stored time is equal to the value in the `creationTime`. This approach will fail, seemingly at random, when the command is executed at a different millisecond. The solution is to test for a reasonable delta:

````Java
assertTrue( Math.abs(System.currentTimeMillis()
- result.getCreateDate().toInstant().toEpochMilli()) < 1000 );
````

* Unit tests for Dataverse Commands live [here](/src/test/java/edu/harvard/iq/dataverse/engine/command/impl).

Happy Testing!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,12 +246,12 @@ public void testCustomOptions() throws CommandException {
dv.setDefaultContributorRole( roles.findBuiltinRoleByAlias(DataverseRole.MANAGER) );

final DataverseRequest request = makeRequest();
List<DatasetFieldType> facets = Arrays.asList( makeDatasetFieldType(), makeDatasetFieldType(), makeDatasetFieldType());
List<DatasetFieldType> expectedFacets = Arrays.asList( makeDatasetFieldType(), makeDatasetFieldType(), makeDatasetFieldType());
List<DataverseFieldTypeInputLevel> dftils = Arrays.asList( makeDataverseFieldTypeInputLevel(makeDatasetFieldType()),
makeDataverseFieldTypeInputLevel(makeDatasetFieldType()),
makeDataverseFieldTypeInputLevel(makeDatasetFieldType()));

CreateDataverseCommand sut = new CreateDataverseCommand(dv, request, new LinkedList(facets), new LinkedList(dftils) );
CreateDataverseCommand sut = new CreateDataverseCommand(dv, request, new LinkedList(expectedFacets), new LinkedList(dftils) );
Dataverse result = engine.submit(sut);

assertEquals( creation, result.getCreateDate() );
Expand All @@ -276,7 +276,7 @@ public void testCustomOptions() throws CommandException {
for ( DataverseFacet df : createdFacets ) {
assertEquals( i, df.getDisplayOrder() );
assertEquals( result, df.getDataverse() );
assertEquals( facets.get(i), df.getDatasetFieldType() );
assertEquals( expectedFacets.get(i), df.getDatasetFieldType() );

i++;
}
Expand Down

0 comments on commit 1d7eadc

Please sign in to comment.