Unit tests are the last type of test we'll cover in this course.
Similar to Kernel tests, in a Unit test, there is no browser to make HTTP requests with, but also no database or service container, so everything needs to be created from scratch.
I do outside-in testing and start with Functional and Kernel tests, so I don't tend to write many Unit tests.
I prefer to use real objects as opposed to mocks and have seen tests that create mocks and only test the mock and not the rest of the code.
I've also seen Unit tests that are very tightly coupled to the implementation, such as asserting a method is only called a certain number of times. This makes the code harder to refactor and could result in a test failing when its functionality is working.
## Your first Unit test
Based on what you've learned so far, let's write a Unit test that we'd expect to pass:
```php
<?php
namespace Drupal\Tests\atdc\Unit;
use Drupal\node\Entity\Node;
use Drupal\node\NodeInterface;
use Drupal\Tests\UnitTestCase;
final class PostWrapperTest extends UnitTestCase {
This test is within the `tests/src/Unit` directory and the equivalent namespace and extends the `UnitTestCase` class.
However, when you run the test, you'll get an error:
> Drupal\Core\DependencyInjection\ContainerNotInitializedException: \Drupal::$container is not initialized yet. \Drupal::setContainer() must be called with a real container.
In a Unit test, there is no database or service container, so you need to use mocks instead.
Update the test to create a mock version of `NodeInterface` instead.
As the mock an instance of `NodeInterface`, it satisfies the assertion and the test passes.