fr.cnes.sirius.validate.validationTool
Class Validate

java.lang.Object
  extended by org.junit.Assert
      extended by fr.cnes.sirius.validate.validationTool.Validate

public class Validate
extends org.junit.Assert

The purpose of this class is to automate the logging of deviations in order to see their evolution. This way, the developers can more easily ensure that a class is still valid even if its components or the classes it uses evolve. This is an extension of the continuous integration to validation.

For each useful method of Assert, Validate provides an implementation that will compute and store the deviation, then call the Assert method. At the end of the test (usually in an @AfterClass method), produceLog() has to be called, otherwise the validation results are not written.

This class is intended as a replacement of the org.junit.Assert class for validation purposes. Its use is similar to the Assert methods of JUnit.

Since:
1.0
Version:
$Id: Validate.java 17578 2017-05-10 12:20:20Z bignon $
Author:
Philippe Pavero
See Also:
Assert
Concurrency :
not thread-safe
Concurrency comment :
two threads can add in the same time their computed deviations instead of adding them one after the other one

Constructor Summary
Validate(Class<?> testClassIn)
          constructor of the Validate object.
 
Method Summary
 void assertEquals(double actual, double nonRegExpected, double nonRegEps, double externalRefExpected, double externalRefEps, String deviationDescription)
          Works as a replacement to the Assert.assertEquals(double, double, double) method.
 void assertEqualsArray(double[] actual, double[] nonRegExpected, double nonRegEps, double[] externalRefExpected, double externalRefEps, String deviationDescription)
          Compute the deviation of each table value and store it to be put in the logs by the produceLogs method.
 void assertEqualsArrayWithRelativeTolerance(double[] actual, double[] nonRegExpected, double nonRegEps, double[] externalRefExpected, double externalRefEps, String deviationDescription)
          Compute the deviation of each table value and store it to be put in the logs by the produceLogs method, but with a relative tolerance.
 void assertEqualsWithRelativeTolerance(double actual, double nonRegExpected, double nonRegEps, double externalRefExpected, double externalRefEps, String deviationDescription)
          Works as a replacement to the Assert.assertEquals(double, double, double) method for a relative comparison.
 void produceLog()
          prints the log in the console and in files.
 void produceLog(String logDir)
          prints the log in the console and in files.
 
Methods inherited from class org.junit.Assert
assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertThat, assertThat, assertTrue, assertTrue, fail, fail
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Validate

public Validate(Class<?> testClassIn)
         throws IOException
constructor of the Validate object. Uses the properties file which path is given. The resource is first searched in the classpath, then outside. Therefore, a resource in the classpath might hide a resource ouside of it, but it is highly unlikely.

Parameters:
testClassIn - the test class, which name will be stored to be printed in the logs.
Throws:
IOException - if an error occurs during the reading of the file
Since:
1.0
Method Detail

assertEquals

public final void assertEquals(double actual,
                               double nonRegExpected,
                               double nonRegEps,
                               double externalRefExpected,
                               double externalRefEps,
                               String deviationDescription)
Works as a replacement to the Assert.assertEquals(double, double, double) method. Compute the deviation and store it to be put in the logs by the produceLogs method. If the test fails, the deviation is still stored, but " : test failed" is added to the message.

Parameters:
actual - the value obtained in the test
nonRegExpected - the value expected by the non-regression reference
nonRegEps - the epsilon allowed with regard to the non-regression reference
externalRefExpected - the value expected by the external reference
externalRefEps - the epsilon allowed with regard to the external reference
deviationDescription - the description of the deviation
Since:
1.0
See Also:
Assert.assertEquals(double, double, double)

assertEqualsArray

public final void assertEqualsArray(double[] actual,
                                    double[] nonRegExpected,
                                    double nonRegEps,
                                    double[] externalRefExpected,
                                    double externalRefEps,
                                    String deviationDescription)
Compute the deviation of each table value and store it to be put in the logs by the produceLogs method.

Parameters:
actual - the array values obtained in the test
nonRegExpected - the array values expected by the non-regression reference
nonRegEps - the epsilon allowed with regard to the non-regression reference
externalRefExpected - the array values expected by the external reference
externalRefEps - the epsilon allowed with regard to the external reference
deviationDescription - the description of the deviation
Since:
1.0
See Also:
Assert.assertEquals(double, double, double)

assertEqualsWithRelativeTolerance

public final void assertEqualsWithRelativeTolerance(double actual,
                                                    double nonRegExpected,
                                                    double nonRegEps,
                                                    double externalRefExpected,
                                                    double externalRefEps,
                                                    String deviationDescription)
Works as a replacement to the Assert.assertEquals(double, double, double) method for a relative comparison. Compute the deviation and store it to be put in the logs by the produceLogs method. If the test fails, the deviation is still stored, but " : test failed" is added to the message.

Parameters:
actual - the value obtained in the test
nonRegExpected - the value expected by the non-regression reference
nonRegEps - the epsilon allowed with regard to the non-regression reference
externalRefExpected - the value expected by the external reference
externalRefEps - the epsilon allowed with regard to the external reference
deviationDescription - the description of the deviation
Since:
1.0
See Also:
Assert.assertEquals(double, double, double)

produceLog

public final void produceLog()
                      throws IOException,
                             URISyntaxException
prints the log in the console and in files. These logs are organised in their package tree, all of it put in the directory given in the setup file.

Throws:
IOException - if there was an error in the manipulation of the files
URISyntaxException - if there was an error in the parsing of the URI of the files
Since:
1.0

produceLog

public final void produceLog(String logDir)
                      throws IOException,
                             URISyntaxException
prints the log in the console and in files. These logs are organised in their package tree, all of it put in the directory given in the setup file.

Parameters:
logDir - name of log file
Throws:
IOException - if there was an error in the manipulation of the files
URISyntaxException - if there was an error in the parsing of the URI of the files
Since:
1.0

assertEqualsArrayWithRelativeTolerance

public final void assertEqualsArrayWithRelativeTolerance(double[] actual,
                                                         double[] nonRegExpected,
                                                         double nonRegEps,
                                                         double[] externalRefExpected,
                                                         double externalRefEps,
                                                         String deviationDescription)
Compute the deviation of each table value and store it to be put in the logs by the produceLogs method, but with a relative tolerance.

Parameters:
actual - the array values obtained in the test
nonRegExpected - the array values expected by the non-regression reference
nonRegEps - the epsilon allowed with regard to the non-regression reference
externalRefExpected - the array values expected by the external reference
externalRefEps - the epsilon allowed with regard to the external reference
deviationDescription - the description of the deviation
Since:
1.0
See Also:
Assert.assertEquals(double, double, double)


Copyright © 2017 CNES. All Rights Reserved.