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

Realm is a mobile database that runs directly inside phones, tablets or wearables.

This repository holds the library to allow Sync client under Android Realm Object Server to encrypt the token saved in SharedPreferences, once the user is authenticated. The encryption uses the Android KeyStore available to generate and uses RSA and AES keys for encryption operations.

StripeCardEntry makes a simple and elegant credit card entry UI of Stripe and ports this to the Android Platform. In a nutshell StripeCardEntry has:

  • Support for Visa, Mastercard & American Express cards.
  • Number validation using Luhn algorithm ensures the user will not enter an invalid number.
  • Date validation ensures the user can only enter a valid expiry date.

An example project with SonarQube integration for proper code review and code structuring.

A woooow splash which like clouds disappear in the sky.

PermissionAcceptor allows to handle runtime permission in Marshmallow (Android 6.0).

Simple builder in plain Java to create requests to the Amazon Product Advertising API.

Amazon challenges all developers that want to use their Advertising API. Especially the creation of the request URL is pretty complex. Therefor I've created this URL Builder, which allows you to create the request URL without having to read the Product Advertisement API documentation or study the used hashing algorithms.

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