C
C#2d ago
πR

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.
No description
27 Replies
greyfox
greyfox2d ago
What does the stack trace say?
πR
πROP2d ago
The one in the screenshot? Its that the assertion failed, because the endpoint does return 500 InternalServerError, instead of for example 200 OK
greyfox
greyfox2d ago
Is the one at the bottom of the screenshot the same? What does your logging say happened?
πR
πROP2d ago
yeah they are all the same for each of the tests.
πR
πROP2d ago
I think there are no logs. Even though I set logs to console im my IntegrationTestWebApplicationFactory class
No description
greyfox
greyfox2d ago
Man, why'd you do that on a webapi?
πR
πROP2d ago
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?
greyfox
greyfox2d ago
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
πR
πROP2d ago
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
greyfox
greyfox2d ago
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.
πR
πROP2d ago
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?
greyfox
greyfox2d ago
You don't know what a console is, do you...
πR
πROP2d ago
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...
greyfox
greyfox2d ago
It does write to the terminal. But it's a background process, it isn't displayed anywhere.
πR
πROP2d ago
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?
greyfox
greyfox2d ago
Where are you hosting the webapi?
πR
πROP2d ago
currently only locally. When I push to github and make a pull requests the github action gets executed.
greyfox
greyfox2d ago
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
πR
πROP2d ago
yeah if I run the test locally
greyfox
greyfox2d ago
No
πR
πROP2d ago
but I mean on the github workflow ?
greyfox
greyfox2d ago
I may have been wrong, console may be correct for this.
πR
πROP2d ago
alright I will have a look. thanks
πR
πROP2d ago
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
No description
πR
πROP2d ago
nvm I found the error. It was because I tried to access JWT Key from appsettings and not env in a sevice.

Did you find this page helpful?