An open API service indexing awesome lists of open source software.

https://github.com/bertcarnell/javaassertextensions

Adds additional Assert methods to the JUnit implementation
https://github.com/bertcarnell/javaassertextensions

java junit

Last synced: 18 days ago
JSON representation

Adds additional Assert methods to the JUnit implementation

Awesome Lists containing this project

README

          

JavaAssertExtensions
====================

Adds additional Assert methods to the [JUnit](http://junit.org/) framework

Please see the document contained [here]( http://bertcarnell.github.io/JavaAssertExtensions)

[![Build Status](https://www.travis-ci.org/bertcarnell/JavaAssertExtensions.svg?branch=master)](https://www.travis-ci.org/bertcarnell/JavaAssertExtensions)
[![codecov](https://codecov.io/gh/bertcarnell/JavaAssertExtensions/branch/master/graph/badge.svg)](https://codecov.io/gh/bertcarnell/JavaAssertExtensions)

### Quick start guide for Maven Users
- See the [bertcarnellMavenMicroRepo](https://github.com/bertcarnell/bertcarnellMavenMicroRepo) for directions on how to include this project in your application or library as a dependency
- Import the methods into your Class

```java
import static com.gmail.bertcarnell.assertextensions.ExceptionAssertExtensions.*;
import static com.gmail.bertcarnell.assertextensions.NumericAssertExtensions.*;
```

- Start writing tests using assertThrows

```java
// check that an exception is thrown in Double.parseDouble("a") using reflection
assertThrows(NumberFormatException.class, new Double(0), "parseDouble", "a");
// check that an exception is thrown from a constructor (Double("a")) using reflection
assertConstuctorThrows(NumberFormatException.class, Double.class.getConstructor(String.class), "a");
// check that an exception is thrown using a Runnable to enclose the method call
assertThrows(NumberFormatException.class, new Runnable(){
@Override
public void run() {
Double.parseDouble("a");
}
});
// check that an exception is thrown using a closure that allows for additional checks in the Catch
assertThrowsAndDoAssertsInCatch(NumberFormatException.class, new ExceptionAssertionsPerformer(){
@Override
public void performThrowingAction() {
Double.parseDouble("a");
}
@Override
public void performAssertionsAfterCatch(Object th) throws Exception {
// if this metod is called, we know that the object is a NumberFormatException or assignable from NumberFormatException
NumberFormatException nfe = (NumberFormatException) th;
assertEquals(nfe.getMessage(), "For input string: \"a\"");
}
});
```
- Write tests using Log Relative Error

```java
// assert that two numbers "agree within 7 digits"
assertEqualsLRE(1234.5678, 1234.5679, 7);
```

- Check the [JUnit](http://junit.org/) tests for the package to see more [examples](https://github.com/bertcarnell/JavaAssertExtensions/tree/master/AssertExtensions/src/test/java/com/gmail/bertcarnell/assertextensions) of tests that pass when the correct Exception is thrown, tests that fail when the wrong Exception is thrown, and tests that fail when no Exception is thrown.

### Deploy this project to the [bertcarnellMavenMicroRepo](https://github.com/bertcarnell/bertcarnellMavenMicroRepo)

This project deploys artifacts to a local git clone which is pushed to [github.com](https://github.com) for use as a remote repo

In the project's pom.xml:

```xml

...





repo

https://raw.github.com/bertcarnell/bertcarnellMavenMicroRepo/master/releases



snapshot-repo
https://raw.github.com/bertcarnell/bertcarnellMavenMicroRepo/master/snapshots

```

If you are using [Netbeans](https://netbeans.org/), these actions can aid in the deployment. In the nbactions.xml file:

```xml




CUSTOM-deploy

deploy


clean
source:jar
javadoc:jar
deploy




snapshot-repo::default::file:../../bertcarnellMavenMicroRepo/snapshots




CUSTOM-deploy-release
deploy-release

clean
source:jar
javadoc:jar
deploy


repo::default::file:../../bertcarnellMavenMicroRepo/releases



```

The artifacts can also be deployed on the command line:

```
mvn clean source:jar javadoc:jar deploy -DaltDeploymentRepository=snapshot-repo::default::file:../../bertcarnellMavenMicroRepo/snapshots
mvn clean source:jar javadoc:jar deploy -DaltDeploymentRepository=repo::default::file:../../bertcarnellMavenMicroRepo/releases
```