Dotnet webapi test failing on GitHub Workflow
Hey everyone, I am currently creating a dotnet webapi and just got into unit- and integration-testing. So I wrote some test with xUnit and TestContainers. Running this tests locally with dotnet test works fine. The tests success and everything is good.
Now I created a github workflow (which is also completely new to me) to automate this tests. However the webapi returns InternalServerError in the tests when running in the workflow.
Could somebody please help me to find the error?
The GitHub repo can be found at: https://github.com/Pierre808/NuvellAPI
I added the beginning of the log message as screenshot.
GitHub
GitHub - Pierre808/NuvellAPI
Contribute to Pierre808/NuvellAPI development by creating an account on GitHub.

27 Replies
What does the stack trace say?
The one in the screenshot? Its that the assertion failed, because the endpoint does return 500 InternalServerError, instead of for example 200 OK
Is the one at the bottom of the screenshot the same?
What does your logging say happened?
yeah they are all the same for each of the tests.
I think there are no logs. Even though I set logs to console im my IntegrationTestWebApplicationFactory class

Man, why'd you do that on a webapi?
I mean it was only for testing to find the error with the gh actions. but it still doesn't log anything.
How would I do it correctly?
Logging sent to the console isn't persisted. You should write to a text file or a database or something.
If you didn't add any logging at all it would be more useful because then at least (if hosted on Windows) the exception and stack trace would be logged to the Event Viewer
I just started with this project. I will add logging to a file later.
For now I just wanted to find out why this test fail with the github workflow, but work locally. This is why I thought logging to the console would show me the error
Can't tell with the lack of logging.
Could be any number of things, a resource isn't accessible, or a permission error, or a missing dll, or anything really.
so logging to console is simply not possible in a webapi? I will need to add a log file? and how would I be able to see this log file within the github workflow, when it fails?
You don't know what a console is, do you...
Probably now what I thought. I mean I work with the terminal everyday, and I thought logging to console would simply print to the terminal where it gets executed...
It does write to the terminal. But it's a background process, it isn't displayed anywhere.
oh I see. Okay then I will just integrate propper logging with a log file. If I configure this in my programm.cs, it should also apply for the test rigth?
Also is there a way to access this logging file after the github workflow failed?
Where are you hosting the webapi?
currently only locally. When I push to github and make a pull requests the github action gets executed.
GitHub
NuvellAPI/.github/workflows/run-test.yml at master · Pierre808/Nuve...
Contribute to Pierre808/NuvellAPI development by creating an account on GitHub.
Ok, if it's running locally then the text file it'll be logged on your local machine on whatever file path you designate as the log folder
yeah if I run the test locally
No
but I mean on the github workflow
?
I may have been wrong, console may be correct for this.
alright I will have a look. thanks
My workflow tells me:
Results File: /home/runner/work/NuvellAPI/NuvellAPI/TestResults/_fv-az1267-395_2025-03-02_16_52_25.trx
Where can I find this file? maybe there are more infos? Because having the log to console shill doesn't show any actual errors why I get InternalServerError

nvm I found the error. It was because I tried to access JWT Key from appsettings and not env in a sevice.