TestABean


Source link: https://github.com/sergiandreplace/TestABean

#TestABean

"Tired of testing beans (aka: objects with just gettes/setters and no logic)? Do not test them!"

"But,but,but... They are code, so they need to be tested."

"So test them! But you don't have to write the tests by yourself!"

"But, but, but... how?"

"I'm happy you made that question..."

TestABean is a library intended to help you perform basic testing on plain data objects (or Beans to generalize).

Usage

Just execute:

new TestABean(MyBean.class).test();

It will check the following:

  • All the declared fields should have a getter and a setter (or a "is" method for getter in case of booleans)
  • All the declared fields can perform a set and then retrieve the same value with a get (equals used)
  • All the declared fields support transitive property. So, after:
a.setValue(x);
 b.setValue(a.getValue());
 c.setValue(b.getValue());

The following should be true

c.getValue().equals(x);

The retrieval and transivite checks are run 100 times each by default on each field with different random values.

Adding it to your project

Gradle it!

 testCompile 'com.sergiandreplace.testabean:testabean:1.0.1'

Configuration

When instancing your TestABean object, you can provide a Configuration object with different parameters:

Configuration configuration=new Configuration.Builder()
  .setGeneratorFactory(generatorFactory)  // Uses a different GeneratorFactory

// See later for further discussion
  .setExceptions("readOnlyField") // Sets a list of fields to not check (readonly, with logic, etc)
  .setTestingRepetitions(50) // Sets the number of times tests will be repeated. 100 by default.
  .build();
 new TestABean(MyBean.class, configuration).test();

Generators

Generators are responsible for creating new random values to test getters and setters. By default, generators are made for primitives and their boxed classes. In order to create a new one, you must extend the class Generator and use the annotation @TargetClass to define which classes will be affected by this generator (ex: IntGenerator targets both Integer and int); then, add your generator to a GeneratorFactory instance and supply it via constructor;

Exceptions

In some cases, there are fields we don't want to check for many reasons (read only fields, complex data types, etc). If this is the case, you can make TestABuild ignore them. You can do it in two ways:

  • With the setExceptions method of the Configuration Builder
  • Annotating your field with @NotABeanField

TODO

This is just an initial version and there is room for a lot of improvement. These are some things in the roadmap:

  • Ability to inject new checks
  • Recursive check for nested classes
  • Increase configuration for more flexible tests

License

 Copyright 2016 Sergi Martínez  Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License. You may obtain a copy of the License at
  http://www.apache.org/licenses/LICENSE-2.0  Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 

Resources

Reactive Extension (Rx) Adaptor for Netty.

ResideLayout is an Android Layout which has a same function like RESideMenu.

Based on SlidePanelLayout in support v4 library. Can be used on Android 1.6

Android Floating Label Widgets is a set of input widgets with a hint label that floats when input is not empty.

This library has lots of interfaces and helper classes to help you either extend it and/or change the existing behavior:

  • LabelAnimator
  • ItemPrinter
  • ItemPicker

SLATE is a light-weight NATIVE cross-platform template engine for mobile devices.

Android library to easily queue background and UI tasks.

So what does it exactly do?

If you are working on Android you probably have ended up using AsyncTasks to do background tasks and then have a response on the UI Thread. Well, author confesses: "I HATE ASYNCTASKS".

SeekBarHint allows to add a SeekBar widget witch is moved and updated according to the SeekBar position.

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