Skip to content

nginate/commons-testing

Repository files navigation

Overview

These are helper classes for some of our favourite test frameworks and old good vanilla java as well. Use it as test dependency if you'll find it useful.

Test frameworks dependencies

Build status

Distribution

Maven
    <repositories>
       <repository>
          <id>jcenter</id>
          <url>http:https://jcenter.bintray.com</url>
          <snapshots>
            <enabled>true</enabled>
            <updatePolicy>never</updatePolicy>
            <checksumPolicy>warn</checksumPolicy>
          </snapshots>
          <releases>
             <enabled>true</enabled>
             <checksumPolicy>warn</checksumPolicy>
          </releases>
       </repository>
    </repositories>
    
    <dependency>
        <groupId>com.github.nginate</groupId>
        <artifactId>commons-testing</artifactId>
        <version>1.0.0</version>
    </dependency>
Gradle
    repositories {
        jcenter()
    }
    
    dependencies {
        compile 'com.github.nginate:commons-testing:1.0.0'
    }

What's there in this bundle?

  • Conditions

AssertJ is great framework for making test assertions, but it requires writing own conditions. These will allow to make long-chained assert on a single test subject.

    assertThat(obj)
        .isNotNull()
        .has(nullIn(Obj::getNullField))
        .has(empty(Obj::getCollectionField))
        ...
        .has(nonNullIn(Obj::getNonNullField))
  • Unique value generation

In order to remove dependency on magic numbers in test, we often use just random values. But the problem is that we need test that are generating same output no matter how many times we run them. So the real goal for test value is to make it rather predictable and globally unique for whole build than just randomize each time.

    Long long1 = uniqueLong();
    Long long2 = uniqueLong();
    
    assert long1 < long2;
    
    Short short1 = uniqueShort();
    
    assert short1 > 0;
    
    Date date1 = uniqueDate();
    Date date2 = uniqueDate();
    
    assert date2.isAfter(date1);
    assert date2.getTime() - date1.getTime() == 1000

License

WTFPL