auto inject for spock framework


License

License

Categories

Categories

Spock Application Testing & Monitoring
GroupId

GroupId

com.github.xiaozhukk
ArtifactId

ArtifactId

spock-inject
Last Version

Last Version

1.0.0
Release Date

Release Date

Type

Type

jar
Description

Description

auto inject for spock framework
auto inject for spock framework
Project URL

Project URL

https://github.com/xiaozhukk/spock-inject
Source Code Management

Source Code Management

https://github.com/xiaozhukk/spock-inject

Download spock-inject

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.xiaozhukk/spock-inject/ -->
<dependency>
    <groupId>com.github.xiaozhukk</groupId>
    <artifactId>spock-inject</artifactId>
    <version>1.0.0</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.xiaozhukk/spock-inject/
implementation 'com.github.xiaozhukk:spock-inject:1.0.0'
// https://jarcasting.com/artifacts/com.github.xiaozhukk/spock-inject/
implementation ("com.github.xiaozhukk:spock-inject:1.0.0")
'com.github.xiaozhukk:spock-inject:jar:1.0.0'
<dependency org="com.github.xiaozhukk" name="spock-inject" rev="1.0.0">
  <artifact name="spock-inject" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.xiaozhukk', module='spock-inject', version='1.0.0')
)
libraryDependencies += "com.github.xiaozhukk" % "spock-inject" % "1.0.0"
[com.github.xiaozhukk/spock-inject "1.0.0"]

Dependencies

compile (1)

Group / Artifact Type Version
org.spockframework : spock-core jar 1.2-groovy-2.4

Project Modules

There are no modules declared in this project.

spock-inject

auto inject dependencies for spock framework

help Mock and inject beans for Spock unit test framework.

some framework(eg: Spring) help manage beans relations on the runtime, and probability have no setter method for dependent bean. it is hard to Mock the dependent beans.

this extension will make it easy to achieve this purpose by only several Annotations.

@Subject indicate the Object to be tested. this annotation is primitive provided by Spock framework, and we just reuse it. @Mock indicate Objects/beans are required by the Object which to be tested

Repository

<dependency>
  <groupId>com.github.xiaozhukk</groupId>
  <artifactId>spock-inject</artifactId>
  <version>1.0.0</version>
</dependency>

How to use

run SpockAnnotation.init(this) in the setup method

eg:

class Foo {
    @Resource
    private Bar bar;

    public void methodToBeTested() {
        bar.method1();
        // ...
    }
}

class Bar {
    public boolean method1() {
        // ...
    }
}

class FooTest extends Specification{
    @Subject
    Foo foo
    @Mock
    Bar bar

    void setup() {
        SpockAnnotation.init(this)
    }

    def "foo test"() {
        given:
        bar.method1() >> true

        when:
        foo.mehodToBeTested()

        then:
        1 * bar.method1()
    }
}

Versions

Version
1.0.0