exercism / csharp

Exercism exercises in C#.
https://exercism.org/tracks/csharp
MIT License
344 stars 346 forks source link

How to debug exercises? #1395

Open danielkerschke opened 4 years ago

danielkerschke commented 4 years ago

Not so sure if this forum is still active, but I figured asking can't hurt. C# is the second language I'm learning after Python, and it's the first time I've used Visual Studio.

For some reason, the debug / execute buttons are always greyed out. I'm not sure why. It may be because there isn't a main method, or because the code isn't part of some project. I have tried adding the code into a blank hello-world file, and that works some of the time, but for some exercises it isn't clear to me what the input should be. Maybe this is a common problem. I am sure there is a better way to do it and I would appreciate any help with this.

ErikSchierboom commented 4 years ago

Hi! Exercises are indeed not designed as stand-alone applications, but as libraries. This means that you can't run them by themselves. However, each exercise has a test suite and all C# IDE's support debugging tests. See https://docs.microsoft.com/en-us/visualstudio/test/run-unit-tests-with-test-explorer?view=vs-2019 That should allow you to debug the code based on a test.

wolf99 commented 4 years ago

Hi @danielkerschke , were you able to figure this out? Will we close this issue?

Gautzilla commented 2 years ago

Hey everyone, Sorry to undig the thread, but I would love to have some extra info about that. I don't fully understand how I am supposed to debug my test.

For example, in any application, I'm used to write "Console.WriteLine(foo)" to display something in order to check if my code does what I wanted it to do.

How could I do something similar with Exercism tests? I've been browsing the net for an hour without finding any solution and I'm kinda lost..

Thanks!

ErikSchierboom commented 2 years ago

@Gautzilla Currently, you can't really do that as there were some issues with console output in the test runner. We've been preparing an upgrade to the test runner and exercises that will allow you to do this in the future. For now, the best option you have is to use the CLI to run the tests on your local machine, as most C# IDE's have good test debugging support.

Gautzilla commented 2 years ago

Hey Hey @ErikSchierboom Thanks for your answer, and for the amazing work btw!

I indeed use the CLI to solve exercises in VS, and a workaround that I found is adding a Console App project to my solution for being able to quickly test methods with the ability to print outputs in the console.

Thanks again!