How to run/test code in visual studio code? - visual-studio

How can I run/text code in visual studio code? What I mean if, for example, I have the following code:
i = 0
while i < 5:
print("test")
i += 1
then I would like to get the output:
test
test
test
test
test
I used jupyter notebook before and this was possible but I can't do this in vscode and they're forcing me to use vscode.

Press F5. You can set a breakpoint by clicking to the left of you line number. See VS Code Debugging for more information. You'll need to install the ms-python extension to get python support (see the above link). Naturally, you can simply invoke your compiler in the terminal as well (Control+` to bring up terminal).

Related

how to switch between compilers when the server is written in python and client in cpp?

I am currently using Visual Studio IDE ,I worked with VS Code and using diffrent coding languges is very easy using the VS code. How ever in my current project I need to work with the Visual Studio IDE . My problem is that in my project the code for the server is written in Python and the code for client is written in CPP. For some reason I cant manage to run the CPP file , only the PYTHON file . In other words if I press Start and currently the tab is in the client code (that is written in Cpp) , the PYTHON code is compiled and not the CPP code , how do I change the compilers?
I tried watching sevrel videos on youtube such as that :
https://www.youtube.com/watch?v=_a3b8fCznQI
but it did not help .
I add picture of the files that are currently in the same folder :
I added 2 pictures.
the first one is showing the start button that I press
the second picture is shwoing what happned after I press the start button.as you can see insted of runng the cpp file it runs the python file.
edit:
I added this pic to show that now I have to python files in my Server_python project.
the first is : Server_python.
py the second is: AES_key.py .
when I press Project and then press Set as Sturtup Project I run the the server_python.py code and not the AES_key code . how to make the VS run the AES_key using the "set As sturtup Project" ?

visual studio code "launch json" on run, how to set debug console as default

I went to user settings to set the debug console to default (when I try to debug now the default console is terminal. I lose the small debug icons to skip, stop etc even when I manually select debug console). I am watching Python tutorials using Vs Code and his default is debug. How can I do this?
Secondly, when I try to run or debug, I am prompted to open LaunchJS, even if it is already open. I attempted to run it using the debug selection "current file, integrated terminal" and also "Python: Attach". Neither will work although the JSON file has these options. I looked at some MS videos but I am not understanding the problem.
Any help is appreciated. Thanks.
I found the answer at this link: https://code.visualstudio.com/docs/python/python-tutorial
I had not selectd a Python interpreter which establishes a python workspace. Was just trying to run with debugger. A simple program now runs. My guess is that the Python tutorial I selected is too old to follow with this version of VS Code, since I am unfamiliar with any version of VS Code.
Thanks.

Use a console window when debugging unit-tests in Visual Studio

When I debug a unit-test with Visual Studio 2017, all the console output is logged and I can examine it by clicking the "Output"-link in the result box of the unit-test (I'm using the built-in Test-Explorer).
However, since I do log a lot to console at runtime which is even color coded so important stuff is more visible, I can't see this color coded output using the "Output"-link, because it's just plain black text on white background.
Is it possible that Visual Studio shows all the output directly in a console window when debugging the tests so I see the output as I would see it when actually running the application outside of a test?
You cannot (or it is very tricky at least) open a console window from a unit test - I've tried with the top 2 answers from the following post, and they didn't work: Show Console in Windows Application?
You can make the Debug.Write... methods write to the Console when you are running/debugging the application itself (not the unit tests) with this code, though:
ConsoleTraceListener listener = new ConsoleTraceListener();
Debug.Listeners.Add(listener);
Any calls to Debug.Write... methods after this code will also output to the console.
Standard output is the only way to display the test output, when we use some output method in our test like Debug.WriteLine(); Console.WriteLine(); etc.
I also tried to change the font of the test output but it seems there is no that option is VS 2017, even someone though someone mentioned this before:
Is there a way to change the Font used in the VS2012 Test Output Window?
Similar case discussed in this thread, even some reply claimed that we could manually launch the console window, but they are 100% sure about it.
If you really need change the font or the color of the test output, in Visual Studio you go to Help -> Send feedback to VS developing team to provider your suggestion .

Attaching MonoDevelop debugger to NUnit test run on OS X

Question as per the title really.
I'm looking for a way to step through running unit tests using MonoDevelop on OS X in the same way you can with Visual Studio (by attaching the debugger manually to the nunit process).
If this is possible on MonoDevelop (on OS X) then it's not obvious how. Would appreciate any pointers.
Build your code as normal, then copy the exes, dlls and mdb files to your other computer.
On your debugger host set the following environment variable and run monodevelop:
$ export MONODEVELOP_SDB_TEST=1
$ monodevelop
(you might need to edit the actual script that monodevelop is launched with and add the first line)
Fire up monodevelop, load your solution, set a break point and then click Run > Debug With > Custom Mono Soft Debugger.
Once the dialog appears, replace 127.0.0.1 with the IP of your debugger. Then click "Listen"
Then, on the other host run :
$ mono --debug \
--debugger-agent=transport=dt_socket,address=IP:PORT \
nunit.console.exe yourtest.dll
Replace IP and PORT with the values given on the debugger.
So you are wanting to run NUnit and then attach to the running process?
I think the only way to debug NUnit tests are from within a MonoDevelop NUnit project. From there you can hit the Debug menu item, and it will start NUnit for you and handle your breakpoints, etc.
Note that you will have difficulty getting it to work with MonoTouch, see here.

Redirecting 'nunit-console' output to the Visual Studio output window

I am testing an F# project using NUnit. On the debug tab of project configuration I have set the debugger to use an external program which is nunit-console here and the working directory to the debug folder of my project. I prefer using nunit-console with the debugger since the GUI version doesn't hit the test file's breakpoints.
When I debug the test the console window appears and disappears and there is no chance to read the output. I have tried Console.Readline(), but it doesn't work because when I directly run the test from a terminal using nunit-console, it fails due to this command.
Is there a way to redirect the nunit-console output to the Visuals Studio's output window?
UPDATE: I could use Thread.Sleep() to delay the nunit-console.exe when I run the test from the console. But from Visual Studio it doesn't happen so I am pretty sure that nunit-console.exe fails to read the test file when the command is issued by Visual Studio. Still, it would be very nice to be able to read the console output, thus the redirection is still desirable.
Either use Tools->Options...->Debugging->General:"Redirect all Output Window text to Immediate Window" and then make sure that the "Immediate Window" is visible with Debug->Windows->Immediate.
Or use NUnit's "/wait" command line option.
Unless I am missing something, you should be able to hit all your breakpoints with the GUI as well, set the startup project to nunit.exe and pass the name of your test DLL as a command line parameter. You will hit the breakpoints in Visual Studio, and your print statments will be in the GUI's output tab.

Resources