All Projects → hkhc → Electricspock

hkhc / Electricspock

Bridging Robolectric and Spock framework.

Programming Languages

java
68154 projects - #9 most used programming language
groovy
2714 projects

Projects that are alternatives of or similar to Electricspock

Androidut
Android开发中必要的一环---单元测试(Unit Test)
Stars: ✭ 419 (+2518.75%)
Mutual labels:  unit-test, robolectric
Kotlin Android Starter
[Kotlin Android] Kotlin Android starter based MVP/Dagger2/RxJava2/Robolectric/Espresso/Mockito. It provides a generator to fast create a Kotlin Android project.
Stars: ✭ 589 (+3581.25%)
Mutual labels:  robolectric
robot-testing-framework
Robot Testing Framework (RTF)
Stars: ✭ 12 (-25%)
Mutual labels:  unit-test
Android Gif Example
Gif RecyclerView in MVP using Dagger 2 + Retrofit 2 + Moshi + RxJava 2 + Glide 4 with JUnit and Espresso tests written in Kotlin + Kotlin DSL!
Stars: ✭ 334 (+1987.5%)
Mutual labels:  robolectric
Android Jetpack Playground
Pet project for cutting edge Android development with Jetpack
Stars: ✭ 266 (+1562.5%)
Mutual labels:  robolectric
Typescript Webpack Starter
⚡ create-ts-lib: A Starter Kit and a CLI to create your TypeScript / ES6 module bundled by Webpack without thinking about build or unit tests configurations. 🏠
Stars: ✭ 358 (+2137.5%)
Mutual labels:  unit-test
conan-gtest
[OBSOLETE] The recipe is now in https://github.com/conan-io/conan-center-index
Stars: ✭ 11 (-31.25%)
Mutual labels:  unit-test
Gut
Godot Unit Test. Unit testing tool for Godot Game Engine.
Stars: ✭ 670 (+4087.5%)
Mutual labels:  unit-test
Httptest
Qiniu httptest utilities
Stars: ✭ 571 (+3468.75%)
Mutual labels:  unit-test
Utest.h
🧪 single header unit testing framework for C and C++
Stars: ✭ 315 (+1868.75%)
Mutual labels:  unit-test
Entwine
Testing tools and utilities for Apple's Combine framework.
Stars: ✭ 306 (+1812.5%)
Mutual labels:  unit-test
Goreporter
A Golang tool that does static analysis, unit testing, code review and generate code quality report.
Stars: ✭ 2,943 (+18293.75%)
Mutual labels:  unit-test
Clean Mvvm Archcomponents
👽 Android app consuming Star Wars API.Built with clean architecture ,MVVM pattern, Koin , Coroutines + Flows ,Architecture Components, Data Binding , Firebase , Unit/UI Tests ,Motion Layout
Stars: ✭ 285 (+1681.25%)
Mutual labels:  robolectric
Fflib Apex Mocks
An Apex mocking framework for true unit testing in Salesforce, with Stub API support
Stars: ✭ 253 (+1481.25%)
Mutual labels:  unit-test
Robolectric
Android Unit Testing Framework
Stars: ✭ 5,372 (+33475%)
Mutual labels:  robolectric
Robolectric-Instrumentation
Emulation of Android Instrumentation Framework API for Robolectric
Stars: ✭ 27 (+68.75%)
Mutual labels:  robolectric
Ward
A modern Python test framework designed to help you find and fix flaws faster.
Stars: ✭ 350 (+2087.5%)
Mutual labels:  unit-test
Unit Test Demo
一步一步介绍如何给项目添加单元测试
Stars: ✭ 766 (+4687.5%)
Mutual labels:  unit-test
Nose2
The successor to nose, based on unittest2
Stars: ✭ 665 (+4056.25%)
Mutual labels:  unit-test
Android Starter
[Android Architecture] Android starter based on MVP/Dagger2/RxJava2/Robolectric/Espresso/Mockito. It provides a generator to fast create a Android template project.
Stars: ✭ 522 (+3162.5%)
Mutual labels:  robolectric

ElectricSpock

Release Travis CI Build Status

What's new

The latest version is 0.9. Past history of the library is over there.

Version 0.8 tested with Robolectric 3.7.1 and Android Gradle Plugin 3.0.1. There is no real code change. Just update version check.

IMPORTANT: Starting from ElectricSpock 0.7, the library will no longer expose the dependent library implicitly. This means you have to add dependencies of Robolectric, Spock Framework and Groovy explicitly. This reduce the chances of version conflict in future. See Installation for details.

For those who stick to Robolectric 3.2, please use version 0.4.1.

For those who stick to Robolectric 3.1, please use version 0.1.

About

The Android test framework Robolectric is designed with JUnit in mind and it does not work well with Spock framework. Fortunately there is a project RoboSpock is designed for that. It configure Robolectric properly under the framework of Spock framework. However it based on some internal source code of Robolectric and it has no official support to Robolectric 3.1 yet. There is an issue for that, but it has been quite some time. So I decided to make my own.

It is heavily based on RoboSpock project. It borrow a lot of code from there, and make some tweak of my own. This project is never possible without the excellent foundation.

Current version (0.9) of the library is tested with Robolectric 3.8.

  • test with Robolectric 3.7.1

Installation (Gradle)

The archive of this project is deployed with jitpack. Add the following to your gradle build script.

Add it in your root build.gradle at the end of repositories:

	allprojects {
		repositories {
			...
			maven { url 'https://jitpack.io' }
		}
	}

Add the dependencies

	// AGP 3.0
	dependencies {
		testImplementation 'com.github.hkhc:electricspock:0.9'
		testImplementation 'org.robolectric:robolectric:3.7.1'
		testImplementation 'org.robolectric:shadows-support-v4:3.4-rc2'
		testImplementation 'org.codehaus.groovy:groovy-all:2.4.12'
		testImplementation 'org.spockframework:spock-core:1.1-groovy-2.4'
	}
	// pre-AGP 3.0
	dependencies {
		testCompile 'com.github.hkhc:electricspock:0.9'
		testCompile 'org.robolectric:robolectric:3.7.1'
		testCompile 'org.robolectric:shadows-support-v4:3.4-rc2'
		testCompile 'org.codehaus.groovy:groovy-all:2.4.12'
		testCompile 'org.spockframework:spock-core:1.1-groovy-2.4'
	}

Then we may just write Spock specification with ElectricSpecification class and Robolectric's @Config annotation

@Config(constants=BuildConfig)
class MySpec extends ElectricSpecification {

    def "Robolectric is enabled"() {

        when: "invoking call to Android API"
            android.util.Log.d("TAG", "Hello world")

        then: "there should not be any error"
            notThrown Exception

    }

}

ElectricSuite

The class ElectricSuite is a helper class to help organize test methods of Specification into group. It is essentially a test class with Suite runner. However we don't need to use @SuiteClasses annotation to specify test classes. Instead the class scan all static inner class as test classes.

For example

class MySpec extends ElectricSuite {

    static class MyInnerSpec1 extends ElectricSpecification {
        [....]
    }

    static class MyInnerSpec2 extends ElectricSpecification [
        [....]
    }

}

Please note that there are a few limitations:

  • We cannot have any test method in the ElectricSuite class. All test methods shall be in the inner test classes of ElectricSuite.

  • (ElecrtricSpock 0.5 fixed this) When using with Spock-reporting-plugin, all inner classes of the same ElectricSuite class shall have the same base class. i.e. Either all of them extend from ElectricSpecification or Specification. Mix of different base classes will cause exception in the reporting plugin. It will be something like OverlappingFileLockException.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].