Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I quickly test a code snippet in Visual Studio (2008)?

Coming from Python where I can just fire up iPython to test out a small snippet of code I'm looking for the same in Visual Studio. Creating projects and classes just to test out a small idea just feels so cumbersome.

like image 634
Berco Beute Avatar asked Oct 21 '10 21:10

Berco Beute


People also ask

How do I test my code in Visual Studio?

Tests can be run from Test Explorer by right-clicking in the code editor on a test and selecting Run test or by using the default Test Explorer shortcuts in Visual Studio. Some of the shortcuts are context-based. This means that they run or debug tests based on where your cursor is in the code editor.

How do I use code snippet in Visual Studio?

Code snippets can be accessed in the following general ways: On the menu bar, choose Edit > IntelliSense > Insert Snippet. From the right-click or context menu in the code editor, choose Snippet > Insert Snippet.

What is snippet in testing?

Snippets are small scripts used in Postman which are used to verify an API. These are pre-developed scripts that can be utilized directly. Thus it helps to save a good amount of time. Snippets can be used in the Pre-request Script and Tests tabs in Postman.

How do you use a snippet?

You can also insert a snippet when logging an activity or leaving a comment on a record using the HubSpot mobile app for Android. There are two ways to add a snippet: Type the # symbol into the text editor. Start typing the snippet shortcut, then select the snippet from the dropdown menu.


3 Answers

You might want to look at LINQPad. It's particularly well suited for LINQ of course, but it's fine for other snippets too.

Personally I just use a simple text editor and Test.cs in a test directory (c:\Users\Jon\Test) and compile from the command line :)

like image 81
Jon Skeet Avatar answered Nov 08 '22 20:11

Jon Skeet


I keep a "Sandbox" project with a console application to do this kind of stuff.

like image 24
Dustin Laine Avatar answered Nov 08 '22 20:11

Dustin Laine


Have a look at the Immediate Window in Visual Studio.

The Immediate window is used at design time to debug and evaluate expressions, execute statements, print variable values, and so forth. It allows you to enter expressions to be evaluated or executed by the development language during debugging.

To display the Immediate window, open a project for editing, then choose Windows from the Debug menu and select Immediate.

like image 33
dtb Avatar answered Nov 08 '22 20:11

dtb