Skip to content

Global Contract Tests via Unit Tests #1962

Description

@benjchristensen

I'm wondering if there is a way for us to create an AbstractTest class that we could implement for each operator that would have a series of specification tests, similar to a TCK that assert core behavior as opposed to the operator functionality.

For example:

  • subscribe and unsubscribe
  • request(Long.MAX_VALUE)
  • request(0)
  • request(n < 0)
  • request(n > 0)
  • scalar
  • vector
  • infinite
  • async and sync variants of each
  • concurrency (where applicable, such as unsubscribe and request)

It would require the implementation classes providing an Observable impl with each operator configured correctly for the various cases, but then the abstract portions could do the pounding and prove the basics for all operators.

This would be a great addition for someone looking to contribute. If someone has the time to tackle this I'd be happy to review the approach, specifications and tests while getting started. We should prove it on a few operators first before making the effort for all of them. For example map, take, merge, groupBy.

Activity

  1. akarnokd commented on Dec 12, 2014

    @akarnokd
    Member

    And perhaps test for the special case of unsubscribe after onError or onCompleted not unsubscribing the downstream since I could do some async work after onError or onCompleted before I tell my downstream how to complete.

  2. abersnaze commented on Dec 12, 2014

    @abersnaze
    Collaborator

    I've been thinking about a general operator testing as well. I think we'll need an alternate iterable implementation of the each operator to use as the expected behavior to assert against.

    actual = Observable.from(input).lift(observableOp).toList().toBlocking().single()
    expected = iterableOp.call(input)
    
  3. davidmoten commented on Jan 14, 2015

    @davidmoten
    Collaborator

    I've had a play with this one. It's not fully unit tested but appears to be working so far and I'm already finding this very useful for testing custom Operators. This may not be what people are envisaging but might nethertheless be useful for pushing discussion.

    The page below demos a sync test for count and an async test for merge.

    https://github.com/davidmoten/rxjava-extras

  4. added this to the 2.0 milestone on Aug 28, 2015
  5. benjchristensen commented on Aug 28, 2015

    @benjchristensen
    MemberAuthor

    Closing in favor of #2783 for 2.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions