1
0
mirror of https://github.com/fafhrd91/actix-web synced 2024-11-27 09:42:57 +01:00
actix-web/actix_test/index.html
2024-05-27 01:16:31 +00:00

25 lines
9.7 KiB
HTML

<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="Integration testing tools for Actix Web applications."><title>actix_test - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-46f98efaafac5295.ttf.woff2,FiraSans-Regular-018c141bf0843ffd.woff2,FiraSans-Medium-8f9a781e4970d388.woff2,SourceCodePro-Regular-562dcc5011b6de7d.ttf.woff2,SourceCodePro-Semibold-d899c5a5c4aeb14a.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../static.files/normalize-76eba96aa4d2e634.css"><link rel="stylesheet" href="../static.files/rustdoc-dd39b87e5fcfba68.css"><meta name="rustdoc-vars" data-root-path="../" data-static-root-path="../static.files/" data-current-crate="actix_test" data-themes="" data-resource-suffix="" data-rustdoc-version="1.80.0-nightly (bdbbb6c6a 2024-05-26)" data-channel="nightly" data-search-js="search-d52510db62a78183.js" data-settings-js="settings-4313503d2e1961c2.js" ><script src="../static.files/storage-118b08c4c78b968e.js"></script><script defer src="../crates.js"></script><script defer src="../static.files/main-20a3ad099b048cf2.js"></script><noscript><link rel="stylesheet" href="../static.files/noscript-df360f571f6edeae.css"></noscript><link rel="icon" href="https://actix.rs/favicon.ico"></head><body class="rustdoc mod crate"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle" title="show sidebar"></button><a class="logo-container" href="../actix_test/index.html"><img src="https://actix.rs/img/logo.png" alt=""></a></nav><nav class="sidebar"><div class="sidebar-crate"><a class="logo-container" href="../actix_test/index.html"><img src="https://actix.rs/img/logo.png" alt="logo"></a><h2><a href="../actix_test/index.html">actix_test</a><span class="version">0.1.3</span></h2></div><div class="sidebar-elems"><ul class="block"><li><a id="all-types" href="all.html">All Items</a></li></ul><section><ul class="block"><li><a href="#structs">Structs</a></li><li><a href="#enums">Enums</a></li><li><a href="#functions">Functions</a></li></ul></section></div></nav><div class="sidebar-resizer"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><h1>Crate <a class="mod" href="#">actix_test</a><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><span class="out-of-band"><a class="src" href="../src/actix_test/lib.rs.html#1-749">source</a> · <button id="toggle-all-docs" title="collapse all docs">[<span>&#x2212;</span>]</button></span></div><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Integration testing tools for Actix Web applications.</p>
<p>The main integration testing tool is <a href="struct.TestServer.html" title="struct actix_test::TestServer"><code>TestServer</code></a>. It spawns a real HTTP server on an
unused port and provides methods that use a real HTTP client. Therefore, it is much closer to
real-world cases than using <code>init_service</code>, which skips HTTP encoding and decoding.</p>
<h2 id="examples"><a class="doc-anchor" href="#examples">§</a>Examples</h2>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>actix_web::{get, web, test, App, HttpResponse, Error, Responder};
<span class="attr">#[get(<span class="string">"/"</span>)]
</span><span class="kw">async fn </span>my_handler() -&gt; <span class="prelude-ty">Result</span>&lt;<span class="kw">impl </span>Responder, Error&gt; {
<span class="prelude-val">Ok</span>(HttpResponse::Ok())
}
<span class="attr">#[actix_rt::test]
</span><span class="kw">async fn </span>test_example() {
<span class="kw">let </span>srv = actix_test::start(||
App::new().service(my_handler)
);
<span class="kw">let </span>req = srv.get(<span class="string">"/"</span>);
<span class="kw">let </span>res = req.send().<span class="kw">await</span>.unwrap();
<span class="macro">assert!</span>(res.status().is_success());
}</code></pre></div>
</div></details><h2 id="structs" class="section-header">Structs<a href="#structs" class="anchor">§</a></h2><ul class="item-table"><li><div class="item-name"><a class="struct" href="struct.Client.html" title="struct actix_test::Client">Client</a></div><div class="desc docblock-short">An asynchronous HTTP and WebSocket client.</div></li><li><div class="item-name"><a class="struct" href="struct.ClientRequest.html" title="struct actix_test::ClientRequest">ClientRequest</a></div><div class="desc docblock-short">An HTTP Client request builder</div></li><li><div class="item-name"><a class="struct" href="struct.ClientResponse.html" title="struct actix_test::ClientResponse">ClientResponse</a></div><div class="desc docblock-short">Client Response</div></li><li><div class="item-name"><a class="struct" href="struct.Connector.html" title="struct actix_test::Connector">Connector</a></div><div class="desc docblock-short">Manages HTTP client network connectivity.</div></li><li><div class="item-name"><a class="struct" href="struct.TestBuffer.html" title="struct actix_test::TestBuffer">TestBuffer</a></div><div class="desc docblock-short">Async I/O test buffer.</div></li><li><div class="item-name"><a class="struct" href="struct.TestRequest.html" title="struct actix_test::TestRequest">TestRequest</a></div><div class="desc docblock-short">Test <code>Request</code> builder.</div></li><li><div class="item-name"><a class="struct" href="struct.TestServer.html" title="struct actix_test::TestServer">TestServer</a></div><div class="desc docblock-short">A basic HTTP server controller that simplifies the process of writing integration tests for
Actix Web applications.</div></li><li><div class="item-name"><a class="struct" href="struct.TestServerConfig.html" title="struct actix_test::TestServerConfig">TestServerConfig</a></div></li></ul><h2 id="enums" class="section-header">Enums<a href="#enums" class="anchor">§</a></h2><ul class="item-table"><li><div class="item-name"><a class="enum" href="enum.PayloadError.html" title="enum actix_test::PayloadError">PayloadError</a></div><div class="desc docblock-short">A set of errors that can occur during payload parsing.</div></li></ul><h2 id="functions" class="section-header">Functions<a href="#functions" class="anchor">§</a></h2><ul class="item-table"><li><div class="item-name"><a class="fn" href="fn.call_and_read_body.html" title="fn actix_test::call_and_read_body">call_and_read_body</a></div><div class="desc docblock-short">Helper function that returns a response body of a TestRequest</div></li><li><div class="item-name"><a class="fn" href="fn.call_and_read_body_json.html" title="fn actix_test::call_and_read_body_json">call_and_read_body_json</a></div><div class="desc docblock-short">Helper function that returns a deserialized response body of a TestRequest</div></li><li><div class="item-name"><a class="fn" href="fn.call_service.html" title="fn actix_test::call_service">call_service</a></div><div class="desc docblock-short">Calls service and waits for response future completion.</div></li><li><div class="item-name"><a class="fn" href="fn.config.html" title="fn actix_test::config">config</a></div><div class="desc docblock-short">Create default test server config.</div></li><li><div class="item-name"><a class="fn" href="fn.init_service.html" title="fn actix_test::init_service">init_service</a></div><div class="desc docblock-short">Initialize service from application builder instance.</div></li><li><div class="item-name"><a class="fn" href="fn.ok_service.html" title="fn actix_test::ok_service">ok_service</a></div><div class="desc docblock-short">Creates service that always responds with <code>200 OK</code> and no body.</div></li><li><div class="item-name"><a class="fn" href="fn.read_body.html" title="fn actix_test::read_body">read_body</a></div><div class="desc docblock-short">Helper function that returns a response body of a ServiceResponse.</div></li><li><div class="item-name"><a class="fn" href="fn.read_body_json.html" title="fn actix_test::read_body_json">read_body_json</a></div><div class="desc docblock-short">Helper function that returns a deserialized response body of a ServiceResponse.</div></li><li><div class="item-name"><a class="fn" href="fn.start.html" title="fn actix_test::start">start</a></div><div class="desc docblock-short">Start default <a href="struct.TestServer.html" title="struct actix_test::TestServer"><code>TestServer</code></a>.</div></li><li><div class="item-name"><a class="fn" href="fn.start_with.html" title="fn actix_test::start_with">start_with</a></div><div class="desc docblock-short">Start test server with custom configuration</div></li><li><div class="item-name"><a class="fn" href="fn.status_service.html" title="fn actix_test::status_service">status_service</a></div><div class="desc docblock-short">Creates service that always responds with given status code and no body.</div></li><li><div class="item-name"><a class="fn" href="fn.to_bytes.html" title="fn actix_test::to_bytes">to_bytes</a></div><div class="desc docblock-short">Collects all the bytes produced by <code>body</code>.</div></li><li><div class="item-name"><a class="fn" href="fn.unused_addr.html" title="fn actix_test::unused_addr">unused_addr</a></div><div class="desc docblock-short">Get a localhost socket address with random, unused port.</div></li></ul></section></div></main></body></html>