Giter Club home page Giter Club logo

espressospoondemo's Introduction

EspressoSpoonDemo

This is a demo project to show how spoon works with espresso.

##Spoon Test runner and reporting tool which runs instrumentation tests. Spoon runs tests on all devices detected by adb. After the tests complete, spoon generates easy, meaningful summary in HTML.

More about Spoon: http://square.github.io/spoon/

##Espresso I took Espresso as my instrumentation tests. Espresso is light-weight instrumentation tests and FAST !

More about Espresso: https://code.google.com/p/android-test-kit/wiki/Espresso

##Setup app/build.gradle

  1. Add classpath to build script dependencies
dependencies {
  classpath 'com.stanfy.spoon:spoon-gradle-plugin:1.0.2'
}
  1. Apply spoon plugin
apply plugin: 'spoon'
  1. Add dependencies
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.1'
androidTestCompile 'com.squareup.spoon:spoon-client:1.2.0'
  1. Add testInstrumentationRunner to defaultConfig
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
  1. Add these lines to fix duplicate files issue
packagingOptions {
  exclude 'LICENSE.txt'
}
  1. Add spoon block
spoon {
  debug = true;
}

##Write test with Espresso

public void testSetMismatchError() {
  // Make screenshot before performance
  Spoon.screenshot(getActivity(), "initial_state");

  // Setup
  onView(withId(R.id.email)).perform(typeText("[email protected]\n"));
  onView(withId(R.id.password)).perform(typeText("lemoncake\n"));

  // Action
  onView(withId(R.id.submit)).perform(click());

  // Make screenshot after performance
  Spoon.screenshot(getActivity(), "after_state");    

  // Test
  onView(withText(R.string.msg_mismatch)).check(matches(isDisplayed()));
}

##Run It's Simple ! Plug-in all devices you want to test or open GenyMotion emulators and execute

$ ./gradlew spoon

To allow spoon taking a screenshot, you need to add WRITE_EXTERNAL_STORAGE permission.

After run, spoon generates spoon folder in app/build directory. You can open index.html and see the result.

https://cdn.rawgit.com/emmasuzuki/EspressoSpoonDemo/master/app/build/spoon/debug/index.html

Also this page is dynamic so you can click on red bar to see details.

##Jacoco Jacoco is a code coverage for Java. It includes following analysis:

  • Line coverage
  • Method coverage
  • Branch coverage
  • Block coverage

Spoon and Jacoco are both reporting tools. Spoon is more like a dev friendly output to find what test is failing and why. While Jacoco is coverage tool where it shows which lines are tested and which are not plus overall metrics of how much your code is tested.

See in action: https://cdn.rawgit.com/emmasuzuki/EspressoSpoonDemo/master/app/build/outputs/reports/coverage/debug/index.html

Setup: app/build.gradle

  1. Enable coverage

    buildTypes {
      debug {
          testCoverageEnabled true
      }
    }
    

Run

$./gradlew createDebugCoverageReport

After run the command, files are generated at app/build/outputs/reports/coverage/. Open index.html and see your report.

##Any Questions ? Please feel free to contact me at [email protected]

espressospoondemo's People

Contributors

emmasuzuki avatar

Watchers

Jeongkuk avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.