EletricSpock


Source link: https://github.com/hkhc/electricspock

ElectricSpock

What's new

The latest version is 0.6

Version 0.6 supports @Config annotation of Robolectric, and tested with Robolectric 3.4.2.

Version 0.5 Compatible with Robolectric 3.3.x. Reorganize yet again, maximal reuse of code from RobolectricTestRunner

Version 0.4 reorganize code structure, new ElectricSuite class

Version 0.3.1 fix an issue to build with jitpack.

Version 0.3 is built as JAR rather than AAR to make gradle detect ElectricSpecification as JUnit class properly.

Version 0.2 is updated to work with Robolectric 3.2.

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.6) of the library is tested with Robolectric 3.4.2.

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 dependency

 dependencies {

testCompile 'com.github.hkhc:electricspock:0.6'  
}

Spock, Robolectric and Groovy are dependencies of ElectricSpock, so it should work without adding these dependencies to build.gradle, but you may override them with the version you prefer.

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.

Resources

EtiyaBadgeTab is a Tab library for Android. As an alternative to the Tab library used on Android, it offers badge support and various customizations.

Graphics related utils for the Android platform.

A helper library to ease the most repetitive codes with simple reusable attributes.

AKUAH can help you with many repetitive tasks of daily life development.

I am using this library in my own projects from quit a time. Now I decided to share in for public use. I have not implemented all the features I used to have in my old library but will keep adding them and some new features.

A semicircular seekbar view for selecting angle from 0° to 180°.

A library for reading Shared Preferences and Database values within the application.

Benefits of using this library

  • No Java Code. Only gradle dependency.
  • Read all the app data within the phone without the need of a browser.
  • See all the Shared Preferences at once or file by file.
  • Copy the value of an individual column of Shared Preference and Database tables to Clipboard.
  • Shows the count of the Shared Preferences in a file and rows in a table.
  • With the help of some additional gradle code, this library will pick up the compileSdk Version, targetSdk Version and Build Tools Version from the main project.

Login effortlessly with different social networks like Facebook, Twitter or Google Plus.

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes