# test.TestServer.session

- **Module:** test.TestServer
- **Package:** libtmux
- **Language:** Rust
- **Kind:** method
- **Source:** https://github.com/libtmux/libtmux-rs/blob/8a648c0894dfffc9303583f753b6c8ae01f2fe76/crates/libtmux/src/test.rs#L778
- **Page:** https://libtmux.org/reference/rs/test-testserver-session/

```
test.TestServer.session(self, options: impl Into<crate::NewSessionOptions>) -> Result<crate::Session, crate::Error>
```

Create a session on this fixture's server.

A test almost always wants a session before it wants anything else,
and reaching through [`TestServer::server`] to say so is noise. Takes
the same options [`crate::Server::new_session`] does, so a test that
needs a start directory or a window name says it here rather than
dropping back to the server.

# Errors

Returns the error tmux gave, including
[`crate::Error::SessionExists`] when the name is taken.

## Example

```rust
let guard = libtmux::test::TestServer::new().await?;
let session = guard.session("work").await?;

assert_eq!(session.name().as_bytes(), b"work");

guard.shutdown().await?;
```
