TestDrive-Surefire

Surefire provider for test-drive java testing library

License

License

GroupId

GroupId

org.bytemechanics
ArtifactId

ArtifactId

test-drive-surefire
Last Version

Last Version

0.2.0
Release Date

Release Date

Type

Type

jar
Description

Description

TestDrive-Surefire
Surefire provider for test-drive java testing library
Project URL

Project URL

https://test-drive.bytemechanics.org
Project Organization

Project Organization

Byte Mechanics
Source Code Management

Source Code Management

https://github.com/bytemechanics/test-drive

Download test-drive-surefire

How to add to project

<!-- https://jarcasting.com/artifacts/org.bytemechanics/test-drive-surefire/ -->
<dependency>
    <groupId>org.bytemechanics</groupId>
    <artifactId>test-drive-surefire</artifactId>
    <version>0.2.0</version>
</dependency>
// https://jarcasting.com/artifacts/org.bytemechanics/test-drive-surefire/
implementation 'org.bytemechanics:test-drive-surefire:0.2.0'
// https://jarcasting.com/artifacts/org.bytemechanics/test-drive-surefire/
implementation ("org.bytemechanics:test-drive-surefire:0.2.0")
'org.bytemechanics:test-drive-surefire:jar:0.2.0'
<dependency org="org.bytemechanics" name="test-drive-surefire" rev="0.2.0">
  <artifact name="test-drive-surefire" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.bytemechanics', module='test-drive-surefire', version='0.2.0')
)
libraryDependencies += "org.bytemechanics" % "test-drive-surefire" % "0.2.0"
[org.bytemechanics/test-drive-surefire "0.2.0"]

Dependencies

compile (4)

Group / Artifact Type Version
org.apache.maven.surefire : surefire-api jar 2.22.1
org.apache.maven.surefire : surefire-logger-api jar 2.22.1
org.apache.maven.surefire : common-java5 jar 2.22.1
org.bytemechanics : test-drive-core jar 0.2.0

test (5)

Group / Artifact Type Version
org.spockframework : spock-core jar 1.2-groovy-2.4
org.codehaus.groovy : groovy jar 2.4.15
net.bytebuddy : byte-buddy jar 1.9.1
org.objenesis : objenesis jar 2.6
cglib : cglib jar 3.2.8

Project Modules

There are no modules declared in this project.

Copy Commons

Latest version Quality Gate Coverage License

Pure java testing framework implementation

Motivation

Spock framework is fantastic but use groovy to test java always will be become a mess. After executing a test that should fail and does not fail. Decided that this must be done in pure java.

Quick start

(Please read our Javadoc for further information)

  1. First of all include the Jar file in your compile and execution classpath.

    Maven

    <dependency>
        <groupId>org.bytemechanics</groupId>
        <artifactId>test-drive</artifactId>
        <version>X.X.X</version>
        <type>test</type>
    </dependency>
  2. In your maven pom.xml activate the surefire test-drive provider by adding the corresponding dependency

     <build>
     	<plugins>
     		<plugin>
     			<groupId>org.apache.maven.plugins</groupId>
     			<artifactId>maven-surefire-plugin</artifactId>
     			<version>X.XX.X</version>
     			(...)
     			<dependencies>
     				<dependency>
     					<groupId>org.bytemechanics</groupId>
     					<artifactId>testdrive-surefire</artifactId>
     					<version>X.X.X</version>
     				</dependency>
     			</dependencies>
     		</plugin>
     	</plugins>
     </build>
  3. In your maven pom.xml activate the suffix you will use (tipically Spec)

     <build>
     	<plugins>
     		<plugin>
     			<groupId>org.apache.maven.plugins</groupId>
     			<artifactId>maven-surefire-plugin</artifactId>
     			<version>X.XX.X</version>
     			<configuration>
     				<includes>
     					<include>*Spec.java</include>
     					(...)
     				</includes>
     			</configuration>
     			(...)
     		</plugin>
     	</plugins>
     </build>
  4. Create your first spec

    • Option 1: non-driven

      import org.bytemechanics.testdrive.Specification;
      import org.bytemechanics.testdrive.annotations.Evaluation;
      import org.bytemechanics.testdrive.annotations.Test;
      import org.bytemechanics.testdrive.Assert;
      
      public class AddIntegerSpec implements Specification {
      
         (...)
      
      	@Test(name="accumulate {} and {} should result with {} with driven test", evaluations = {
      		@Evaluation(name = "one",args = {"1","1","0","2"}),
      		@Evaluation(name = "zero",args = {"0","0","0","0"})
      	})
      	public void accumulate(final int _base,final int _val1,final int _val2,final int _expected){
      
         	int base=_base;
         	int actual=base+_val1+_val2;
         	Assert.assertEquals(actual,_expected);
      	}
         (...)
      }
    • Option 2: non-driven with labels

      import org.bytemechanics.testdrive.Specification;
      import org.bytemechanics.testdrive.annotations.Evaluation;
      import org.bytemechanics.testdrive.annotations.Test;
      import org.bytemechanics.testdrive.Assert;
      
      public class AddIntegerSpec implements Specification {
      
         (...)
      
      	@Test(name="accumulate {} and {} should result with {} with driven test", evaluations = {
      		@Evaluation(name = "one",args = {"1","1","0","2"}),
      		@Evaluation(name = "zero",args = {"0","0","0","0"})
      	})
      	public void accumulate(final int _base,final int _val1,final int _val2,final int _expected){
      
         	int base,actual;
      
         	given:
         		base=_base;
         	when:
         		actual=base+_val1+_val2;
         	then:
         		Assert.assertEquals(actual,_expected);
      	}
         (...)
      }
    • Option 3: driven

      import org.bytemechanics.testdrive.DrivenTest;
      import org.bytemechanics.testdrive.Specification;
      import org.bytemechanics.testdrive.annotations.Evaluation;
      import org.bytemechanics.testdrive.annotations.Test;
      import org.bytemechanics.testdrive.example.AddInteger;
      import org.bytemechanics.testdrive.exceptions.AssertException;
      import org.bytemechanics.testdrive.Assert;
      
      public class AddIntegerSpec implements Specification {
      
         (...)
      
      	@Test(name="accumulate {} and {} should result with {} with driven test", evaluations = {
      		@Evaluation(name = "one",args = {"1","1","0","2"}),
      		@Evaluation(name = "zero",args = {"0","0","0","0"})
      	})
         public DrivenTest accumulateDriven(final int _base,final int _val1,final int _val2,final int _expected){
         	return new DrivenTest() {
      
         		int base,actual;
      
         		@Override
         		public void given() {
         			this.base=_base;
         		}
         		@Override
         		public void when() {
         			this.actual=this.base+_val1+_val2;
         		}
         		@Override
         		public void then() throws AssertException {
         			Assert.assertEquals(this.actual,_expected);
         		}
         	};
         }
         (...)
      }

For additional information please refer example project

org.bytemechanics

ByteMechanics Foundation

Foundation dedicated to provide opensource libraries and resources to simplify developers life

Versions

Version
0.2.0