# How to do integration testing with HTTP.jl?

**URL:** https://discourse.julialang.org/t/how-to-do-integration-testing-with-http-jl/21573
**Category:** Web Stack
**Tags:** question, testing
**Created:** [March 7, 2019, 2:15pm UTC](https://discourse.julialang.org/t/how-to-do-integration-testing-with-http-jl/21573 "2019-03-07T14:15:08Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![non-Jedi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/non-jedi/32/3645_2.png) [@non-Jedi](https://discourse.julialang.org/u/non-Jedi)
#### Post date: [March 7, 2019, 2:15pm UTC](https://discourse.julialang.org/t/how-to-do-integration-testing-with-http-jl/21573/1 "2019-03-07T14:15:08Z")

</div>

I’m building out a package that wraps an API using HTTP.jl. One thing I’m having trouble with is figuring out how to do integration testing. In the past, I’ve used python requests and just used mocking with [responses](https://github.com/getsentry/responses) to do such testing. What have y’all done for integration testing with HTTP.jl? I’ve thought about just spinning up a server with HTTP.jl on a different port to test against, but the API only exists on 80/443, so I can’t justify including an option for specifying the port in the package just so that I can run tests using that option.

---

<div class="post-metadata">

### Author: ![mopg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mopg/32/3368_2.png) [@mopg](https://discourse.julialang.org/u/mopg)
#### Post date: [April 9, 2022, 12:37am UTC](https://discourse.julialang.org/t/how-to-do-integration-testing-with-http-jl/21573/2 "2022-04-09T00:37:57Z")

</div>

@non-Jedi did you ever find out a solution to this? I looked into using [https://github.com/getsentry/responses](https://github.com/getsentry/responses) but that seems to heavily depend on using Python’s requests library, so I don’t think that’s compatible with HTTP.jl.

---

<div class="post-metadata">

### Author: ![mopg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mopg/32/3368_2.png) [@mopg](https://discourse.julialang.org/u/mopg)
#### Post date: [April 12, 2022, 5:31am UTC](https://discourse.julialang.org/t/how-to-do-integration-testing-with-http-jl/21573/3 "2022-04-12T05:31:19Z")

</div>

For future: I have found this blog post to be satisfactory to test my package: [Working with the HTTP Protocol and Forms in Julia | by Erik Engheim | Medium](https://erik-engheim.medium.com/working-with-the-http-protocol-in-julia-5697d531f0c7).

I used `t = @async HTTP.serve(router, ip"127.0.0.1", 8080)` to run the server and then after my tests, ran `schedule(t, InterruptException(), error=true)`. Probably not the prettiest, but it works.

---

<div class="post-metadata">

### Author: ![non-Jedi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/non-jedi/32/3645_2.png) [@non-Jedi](https://discourse.julialang.org/u/non-Jedi)
#### Post date: [April 12, 2022, 4:36pm UTC](https://discourse.julialang.org/t/how-to-do-integration-testing-with-http-jl/21573/4 "2022-04-12T16:36:43Z")

</div>

I never did figure out any way other than just running a server like you ended up doing. It’d probably be worthwhile to open an issue on the HTTP.jl repo to either implement a way of mocking http request calls or documenting how to do so (I suspect doing so might be relatively easy).

---

<div class="post-metadata">

### Author: ![fredrikekre](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fredrikekre/32/1688_2.png) [@fredrikekre](https://discourse.julialang.org/u/fredrikekre)
#### Post date: [April 12, 2022, 5:38pm UTC](https://discourse.julialang.org/t/how-to-do-integration-testing-with-http-jl/21573/5 "2022-04-12T17:38:43Z")

</div>

There is [BrokenRecord.jl](https://github.com/JuliaTesting/BrokenRecord.jl) which you can record and replay server responses with.

---

<div class="post-metadata">

### Author: ![AsafManela](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/asafmanela/32/4863_2.png) [@AsafManela](https://discourse.julialang.org/u/AsafManela)
#### Post date: [March 3, 2025, 1:57pm UTC](https://discourse.julialang.org/t/how-to-do-integration-testing-with-http-jl/21573/6 "2025-03-03T13:57:33Z")

</div>

The [Mocking.jl](https://juliatesting.github.io/Mocking.jl/stable/) package solved this. Leaving this here in case anyone goes down this rabbit hole.
