Giter VIP home page Giter VIP logo

nitrogen-test-runner's Introduction

Nitrogen Test Runner

A gradle plugin and testing library that lets you quickly and easily switch between JVM and Emulator/Device for running Android Instrumentation tests.

๐Ÿšง This project is in alpha, use with caution as the API is still under active development and may change

Getting Started

Create a new module to hold your Instrumentation tests

Apply the nitrogen plugin and the kotlin android plugin:

plugins {
    id("tech.sarahgallitz.nitrogen-plugin") version "0.0.1"
    id("org.jetbrains.kotlin.android")
}

Set the test module applicationId:

android {
    defaultConfig {
        testApplicationId = "demo.uiTests"
    }
}

Add a dependency on the android-application module which the tests should run against, and add the nitrogen test library:

dependencies {
    implementation(project(":demo:app"))
    implementation("tech.sarahgallitz:nitrogen:0.0.1")
}

Don't forget to add androidx and JUnit dependencies as appopriate to your project. Nitrogen works with the AndroidX testing framework.

Add a nitrogen.config file at the top level of your project, or at the top level of the instrumentation module. The nitrogen.config file should define the following properties:

isRunningOnJVM = true
targetProjectPath = :demo:app

Note: When changing the value of isRunningOnJVM you should run a gradle sync afterwards.

Add your first test:

@RunWith(NitrogenTestRunner::class)
class ExampleNitrogenTest {
    @Test
    fun exampleTest() {
        assertTrue(1 == 1)
    }

    @Test
    fun exampleJVMOnlyTest() {
        skipOnDevice()

        assertTrue(1 == 1)
    }

    @Test
    fun exampleDeviceOnlyTest() {
        skipOnJVM()
        assertTrue(1 == 1)
    }
}

The Tech

Nitrogen is built on top of:

  • AndroidX
  • Robolectric

At gradle configuration time it applies either the android-library plugin (for JVM target) or the android-test plugin (for device target).

Known Issues

Test Android Manifest

Robolectric requires activities to be added to the AndroidManifest of the test module. Currently the nitrogen plugin attempts to autogenerate the AndroidManifest for you, but this has some issues:

  • any existing manifest will be overwritten
  • the manifest generation is pretty dodgy and may not work for all applications

Tests that navigate over multiple screens

It is currently not possible to test real activity to activity navigation when targeting the JVM, please mark these tests with skipOnJVM().

nitrogen-test-runner's People

Contributors

sarah-gallitz avatar mridul-gupta avatar

Stargazers

 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.