# How to use WebApplicationFactory for integration tests together with Hangfire?

**URL:** <https://discuss.hangfire.io/t/how-to-use-webapplicationfactory-for-integration-tests-together-with-hangfire/11327>\
**Category:** question\
**Created:** [June 12, 2025, 7:34am UTC](https://discuss.hangfire.io/t/how-to-use-webapplicationfactory-for-integration-tests-together-with-hangfire/11327 "2025-06-12T07:34:31Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![artyomelfimov](https://dub1.discourse-cdn.com/flex017/user_avatar/discuss.hangfire.io/artyomelfimov/32/3925_2.png) [@artyomelfimov](https://discuss.hangfire.io/u/artyomelfimov)\
**Post date:** [June 12, 2025, 7:34am UTC](https://discuss.hangfire.io/t/how-to-use-webapplicationfactory-for-integration-tests-together-with-hangfire/11327/1 "2025-06-12T07:34:31Z")

</div>

I want to add integration tests to the project. The project also has a Hangfire. I decided to do it using test containers and WebApplicationFactory. But when trying to add to Hangfire services

```auto
services.AddHangfire(config =>
        config.UsePostgreSqlStorage(c =>
            c.UseNpgsqlConnection(
                postgresConnectionString)))

```

Errors occur

Inner exception 1:

`ArgumentException: Couldn't set user (Parameter 'user')`

Inner exception 2:

`KeyNotFoundException: The given key was not present in the dictionary.`

The postgresConnectionString itself is passed correctly. What could be the problem with hangfire and how to use it correctly in the web application factory?

I tried to remove all Hangfire services and replace them with mocks, but it doesn’t work.  
How should i implement WebApplicationFactory with Hangfire service?
