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

A simple Android ImageView implementation which draws a letter on a randomly colored background.

A simple charting library for Android, supporting line- bar- and piecharts, scaling, dragging and selecting.

The Android Action Bar Style Generator allows you to easily create a simple, attractive and seamless custom action bar style for your Android application. It will generate all necessary nine patch assets plus associated XML drawables and styles which you can copy straight into your project.

Use it online here: http://jgilfelt.github.com/android-actionbarstylegenerator

An open source project to provide push notification support for Android - a XMPP based notification server and a client tool kit.

android-checkout is a library for Android In-App Billing (v3). The main goal is to reduce work which should be done by developers who want to integrate in-app purchases in their products. The project is inspired by Volley library and is designed to be easy to use, fast and flexible.

Mobile App testing on 300+ real devices!

  • Save in App Development Costs
  • Reduce Risks with Proactive, Agile Testing
  • Speed Up Time to Market
  • Reduce Operational & Unpredictable Costs
  • Improve App Ratings & Brand Reputation

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