Git Product home page Git Product logo

johncapehart / httptest2 Goto Github PK

View Code? Open in Web Editor NEW

This project forked from cran/httptest2

0.0 1.0 0.0 116 KB

:exclamation: This is a read-only mirror of the CRAN R package repository. httptest2 — Test Helpers for 'httr2'. Homepage: https://enpiar.com/httptest2/, https://github.com/nealrichardson/httptest2 Report bugs for this package: https://github.com/nealrichardson/httptest2/issues

License: Other

R 100.00%

httptest2's Introduction

httptest2: Test Helpers for 'httr2'

Build Status codecov

httptest2 makes it easy to write tests for code and packages that wrap web APIs. Testing code that communicates with remote servers can otherwise be painful: things like authentication, server state, and network flakiness can make testing seem too costly to bother with. The httptest2 package enables you to test all of the logic on the R sides of the API in your package without requiring access to the remote service.

Importantly, it provides contexts that mock the network connection and tools for recording real requests for future offline use as fixtures, both in tests and in vignettes. The package also includes additional expectations to assert that HTTP requests were---or were not---made.

Using these tools, you can test that code is making the intended requests and that it handles the expected responses correctly, all without depending on a connection to a remote API. The ability to save responses and load them offline also enables you to write package vignettes and other dynamic documents that can be distributed without access to a live server.

This package is an adaptation of httptest to work with httr2. Most features work exactly as they do in httptest; see the NEWS.md for the initial release for a summary of what has changed.

Installing

httptest2 can be installed from CRAN with

install.packages("httptest2")

The pre-release version of the package can be pulled from GitHub using the remotes package:

# install.packages("remotes")
remotes::install_github("nealrichardson/httptest2")

Getting started

To start using httptest2 with your package, run use_httptest2() in the root of your package directory. This will

  • add httptest2 to "Suggests" in the DESCRIPTION file
  • add library(httptest2) to tests/testthat/setup.R, which testthat loads before running tests

Then, you're ready to start using the tools that httptest2 provides. For an overview of how to get started, see vignette("httptest2"), and check out vignette("faq") for some common questions. See also the package reference for a list of all of the test contexts and expectations provided in the package.

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.