# perldoc > Test::Unit::Assertion::CodeRef

---
type: CommandReference
command: Test::Unit::Assertion::CodeRef
mode: perldoc
section: 
source: perldoc
---

## Quick Reference

- `Test::Unit::Assertion::CodeRef->new(sub { ... })` — create a delayed assertion from a coderef
- `$assertion->do_assertion(@args)` — evaluate the assertion with the given arguments
- `$self->assert(sub { ... }, @args)` — indirect use via Test::Unit::Test

## Name

Test::Unit::Assertion::CodeRef - A delayed evaluation assertion using a Coderef

## Synopsis

perl
use Test::Unit::Assertion::CodeRef;

my $assert_eq = Test::Unit::Assertion::CodeRef->new(sub {
    $_[0] eq $_[1]
        or Test::Unit::Failure->throw(-text => "Expected '$_[0]', got '$_[1]'\n");
});

$assert_eq->do_assertion('foo', 'bar');
More commonly used indirectly via `assert()`:

perl
$self->assert(sub {
    $_[0] == $_[1]
        or $self->fail("Expected $_[0], got $_[1]");
}, 1, 2);
## Description

This class implements the `Test::Unit::Assertion` interface, allowing assertions to be written in a functional style. It is typically instantiated automatically by `Test::Unit::Test::assert` when a coderef is passed as the first argument.

If `B::Deparse` is available, a failed assertion will display the decompiled coderef (without comments, but still useful).

## Methods

- `->new(\&coderef)` — constructor. Takes a coderef that will be called later with assertion arguments.
- `->do_assertion(@args)` — execute the stored coderef with the given arguments. The coderef should throw a `Test::Unit::Failure` on failure.

## See Also

- [Test::Unit::TestCase](https://metacpan.org/pod/Test::Unit::TestCase)
- [Test::Unit::Assertion](https://metacpan.org/pod/Test::Unit::Assertion)