This project offers an utility class for creating Lighter spy Gradle Projects for test.
This project is licensed under the terms of the MIT license.
Have a Gradle project for test with:
- Mock
Plugins
and MockPluginManager
.- Without this,
Project
will appeal to the network in order to get and apply the plugins, this can be time consuming and if the project use some paid by time platform this could be inadequate.
- Without this,
- Mock
Logger
.
Offers a SpyProjectFactory
class that has:
build()
method builds a Gradle spyProject
with Default builder:pluginManager
field will be mocked.plugins
field will be mocked.logger
field will be mocked.name
field will be Spy Project.
build(final ProjectBuilder builder)
method builds a Gradle spyProject
with provided builder:pluginManager
field will be mocked.plugins
field will be mocked.logger
field will be mocked.
builder
field, that allows to buildProject
without mocking.- This way only 1
ProjectBuilder
instance will exist in the test project.
- This way only 1
SpyProjectFactory
class will be used when using the Gradle API, then:
dependencies {
compile gradleApi()
}
This library make use of Mockito and is already set in the internal dependencies, therefore no need to add it to the project.
- Add repository:
repositories {
maven {
url 'https://dl.bintray.com/gmullerb/all.shared.gradle'
}
}
- Add Test dependency:
dependencies {
testCompile 'all.shared.gradle:spy-project-factory:+'
}
final Project spyProject = SpyProjectFactory.build();
final ProjectBuilder someBuilder = ProjectBuilder.builder()
.withName(..);
final Project spyProject = SpyProjectFactory.build(someBuilder);
Since getPluginManager and getPlugins will be mocked, adding the plugin must be simulated [1], this imply:
- Must manually add any extensions the plugin adds and required by the test [2].
- Must manually add any task the plugin adds and required by the test [2].
spyProject.extensions.add(EXTENSION_NAME, someExtension)
spyProject.tasks.create(TASK_NAME, someTask)
E.g:
final CodeNarcExtension extension = new CodeNarcExtension(spyProject)
spyProject.extensions.add('codenarc', extension)
spyProject.tasks.create('codenarcMain', CodeNarc)
[1] The advantage is that the
Project
will not appeal the network to get the plugins, something that can be time consuming and if the project use some paid by time platform this could be inadequate.
[2] This can allow the mocking or spying of an extension or task.
verify(spyProject.logger)
.debug(..)
final Project someProject = SpyProjectFactory.build.build();
final Project someProject = SpyProjectFactory.build
.withName(..)
.withProjectDir(..)
..
.build();
Clone or download the project[1], in the desired folder execute:
git clone https://github.com/gmullerb/spy-project-factory
- No need, only download and run (It's Gradle! Yes!).
-
To build it:
gradlew
: this will run default task, orgradlew build
.
-
To assess files:
gradlew assessCommon
: will check common style of files.gradlew assessGradle
: will check code style of Gradle's.gradlew checkstyleMain
: will check code style of Java's source files.gradlew checkstyleTest
: will check code style of Java's test files.gradlew pmdMain
: will check code style of Java's source files.gradlew pmdTest
: will check code style of Java's test files.assemble
task depends on these six tasks.
-
To test code:
gradlew test
- This task is finalized with a Jacoco Report.
-
To get all the tasks for the project:
gradlew tasks --all
/src
/main
/java
/test
/java
src/main/groovy
: Source code files.SpyProjectFactory
is where all the magic happens.
src/test/groovy
: Test code files[1].
CHANGELOG.md
: add information of notable changes for each version here, chronologically ordered [1].
[1] Keep a Changelog
Don't forget:
- Love what you do.
- Learn everyday.
- Learn yourself.
- Share your knowledge.
- Learn from the past, dream on the future, live and enjoy the present to the max!.
At life:
- Let's act, not complain.
At work:
- Let's give solutions, not questions.