GithubHelp home page GithubHelp logo

asarkar / coroutines-test Goto Github PK

View Code? Open in Web Editor NEW
3.0 3.0 3.0 70 KB

Includes a JUnit 5 Extension that can dump coroutines on timeout

License: Apache License 2.0

Kotlin 100.00%
dump-coroutines coroutines-test kotlin kotlinx kotlin-coroutines debugging testing junit5 junit junit-extension

coroutines-test's Introduction

coroutines-test

Includes a JUnit 5 Extension that can dump coroutines on timeout. Like CoroutinesTimeout JUnit 4 rule, but built for JUnit 5 and with almost 100% test coverage (yes, I test code that's meant to test others' code).

Requires Java 8 or later. Verified working with the latest JUnit 5 version, which you can find in the gradle.properties.

Installation

You can find the latest version on Bintray. Download

It is also on Maven Central and jcenter.

Usage

The simplest way to get started:

@CoroutinesTimeout(timeout = "PT1S")
class TimeConsumingTest {
    @CoroutinesTimeout(timeout = "PT2S")
    @Test
    fun testOverrideTimeout() {
        runBlocking { delay(1500) }
    }

    @Test
    fun test() {
        runBlocking { delay(800) }
    }
}

See KDoc for more details.

Sample coroutines dump:

Coroutines dump 2020/08/14 16:21:18

Coroutine "coroutine#1":BlockingCoroutine{Active}@78383390, state: SUSPENDED
    at com.asarkar.kotlinx.test.ClassLevelTimeout$testTimeout$1.invokeSuspend(ClassLevelTimeout.kt:16)
	(Coroutine creation stacktrace)
	...
	at com.asarkar.kotlinx.test.ClassLevelTimeout.testTimeout(ClassLevelTimeout.kt:16)
	...
	at com.asarkar.kotlinx.test.CoroutinesTimeoutExtension$interceptTestMethod$testResult$1.call(CoroutinesTimeoutExtension.kt:30)
	...
	at java.base/java.lang.Thread.run(Thread.java:834)

Contribute

This project is a volunteer effort. You are welcome to send pull requests, ask questions, or create issues. If you like it, you can help by spreading the word!

License

Copyright 2020 Abhijit Sarkar - Released under Apache License v2.0.

coroutines-test's People

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  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.