Power Assert for Android


Source link: https://github.com/gfx/android-power-assert-plugin

Power Assert for Android

Power Assert is a language extension which adds extra information when assertions fail. This feature has been invented in Groovy and being spread around other programming languages, and is becoming a fundamental feature for debugging and testing, especially in unit tests: you no longer need to learn a bunch of test matchers such as assertEquals().

This is a Gradle plugin to provide Android with power asserts by modifying Java class files in compilation phases. To use power assert, all you have to do is to depend on android-power-assert-plugin and apply android-power-assert plugin in build.gradle, which automatically enables assert statements unless you makes release build. Thus you can use assert statements both in applications and unit tests.

Usage

This plugin uses assert statements in Java by applying this plugin in build.gradle.

// in the root build.gradle buildscript {

  repositories {

mavenCentral() // or jcenter()
  
}

  dependencies {

classpath 'com.android.tools.build:gradle:1.5.2'

classpath 'com.github.gfx.android.powerassert:plugin:1.5.2'
  
}
 
}
// in a build.gradle of a module apply plugin: 'android' apply plugin: 'com.github.gfx.android.powerassert'

Then, use assert in your program:

// in example's MainActivity.java void onButton2Click() {

  assert findViewById(android.R.id.list).getVisibility() == View.VISIBLE; 
}

This shows the following output when findViewById() returns null:

java.lang.NullPointerException: 25:
  void onButton2Click() {
 26>

assert findViewById(android.R.id.list).getVisibility() == View.VISIBLE; 26:
  
}
 com.github.gfx.powerassert.example.MainActivity.findViewById()=<null> (...stacktrace...) 

Logging

POWERASSERT_VERBOSE=1 shows debug logs including how the plugin spends time in bytecode modification.

POWERASSERT_VERBOSE=2 shows all the extra source code so it might be useful to debug this plugin.

Compatibility

The minor version of this plugin should match with the minor version of Android Gradle Plugin.

That is, android-power-assert-plugin v0.10.x is compatible with Android Gradle Plugin v0.10.x, as well as android-power-assert-plugin v1.1.x is compatible with Android Gradle Plugin v1.1.x.

Author And License

Copyright 2014, FUJI Goro (gfx) [email protected]. All rights reserved.

This library may be copied only under the terms of the MIT License.

See Also

Resources

Some useful utility classes for Android.

This library allows to generate low poly images.

A custom checkbox with animation.

Simple example for flip animation.

SNTP client for Android. Calculate the date and time "now" impervious to manual changes to device clock time.

Apply custom effects on view backgrounds.

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