Back to Dagger

Create Service For Test

docs/current_docs/partials/cookbook/services/_create-service-for-test.mdx

0.20.71.4 KB
Original Source

Create a transient service for unit tests

The following Dagger Function creates a service and binds it to an application container for unit testing. In this example, the application being tested is Drupal. Drupal includes a large number of unit tests, including tests which depend on an active database service. This database service is created on-the-fly by the Dagger Function.

<Tabs groupId="language" queryString="sdk"> <TabItem value="go" label="Go">
go
</TabItem> <TabItem value="python" label="Python">
python
</TabItem> <TabItem value="typescript" label="TypeScript">
typescript
</TabItem> <TabItem value="php" label="PHP">
php
</TabItem> </Tabs>

Example

Run Drupal's unit tests, instantiating a database service during the process:

<Tabs groupId="shell"> <TabItem value="System shell"> ```shell dagger -c test ``` </TabItem> <TabItem value="Dagger Shell"> ```shell title="First type 'dagger' for interactive mode." test ``` </TabItem> <TabItem value="Dagger CLI"> ```shell dagger call test ``` </TabItem> </Tabs>