Rory Becker - DevExpress CodeRush Blog
  • CodeRush for Roslyn: Webinar links

    Following our recent 17.1 webinar on CodeRush for Roslyn, I wanted to follow up with a summary of the links posted in the chat during the Webinar.

    Setup

    CodeRush Setup Wizard

    Previous CodeRush Features of the Week

    T is for Test
    Tab To Next Reference
    Templates
    Debug Visualizer


    Our "Coding at the Speed of Thought" series

    Introduction - CodeRush at the Speed of Thought
    Declaring Types with Templates (CodeRush at the Speed of Thought)
    Template Type Shortcuts (CodeRush at the Speed of Thought)
    Declaring Properties (CodeRush at the Speed of thought)
    Declaring Methods (CodeRush at the Speed of thought)
    Inside Methods (CodeRush at the Speed of Thought)
    Declaring Events (CodeRush at the Speed of Thought)
    Declare from Usage (CodeRush at the Speed of Thought)

    Feature callouts

    Declare Menu – Overview - Documentation
    Symbol Naming Assistant – Overview - Documentation
    Clipboard History – OverviewDocumentation
    Code Metrics – OverviewDocumentation
    Smart Duplicate Line – OverviewDocumentation
    Drop Marker before Jump - Overview - Documentation

    Misc Links
    Extract Interface – Documentation
    Widen Scope – Documentation 
    Widen Scope (Promote to field) – Documentation
    Move Type to Namespace – Documentation
    Reorder Parameters – Documentation

  • CodeRush for Roslyn: XAML support

    XAML is an XML-based language developed by Microsoft, which is widely used in WPF and UWP applications. Visual Studio 2017 helps a lot with editing XAML: features like IntelliSense, tag auto-close and code fold are very useful and increase productivity, but what if your IDE could help you even more?

    With the help of CodeRush for Roslyn, Visual Studio will better understand the relationship between the markup and the code. This will help you in many aspects, especially, navigation.

    Let’s take a look at the most useful CodeRush for Roslyn features for XAML. Most examples are shown using the source code of the Material Design In XAML Toolkit.

    Find References

    You can use the References window in XAML. It will search for references in code and markup files across the solution.

    Tab to Next Reference

    What’s the fastest way to find symbol references within a file? You can use search, but it’s not very smart and may find too much. We invented the fastest way to find symbol references in a file. Just hit Tab while you are on an identifier and you will immediately jump to the next reference to it. Keep hitting tab and jumping to successive references. If you accidentally overshoot the reference you’re looking for, don’t panic. Just use Shift+Tab to move back through the references already seen. All references are highlighted for you to have a clear vision of your code while moving among symbol usages.

    Jump to Resource

    Seeing an image or resource dictionary in your code and wondering what is it? With CodeRush for Roslyn, you can press F12 to instantly open it.

    Jump to Symbol Declaration

    Navigates to the declaration of an identifier (in markup or Code Behind) from any reference in XAML file: tag, markup extension, templated parent, etc.

    Templates

    The whole power of CodeRush Templates is available in XAML! You can use templates from the template library and even create your own to maximize your productivity.

    Let’s see some examples in action.


    XAML Markup Formatting

    Format XAML Document

    XAML markup often has deep and complex structure, and if, while editing, the formatting is less than optimal, you may experience difficulties understanding its structure. You can fix it manually, but that can take a lot of work. You could use an online XML formatter, but that would involve copy/pasting and switching out to a browser. Now there’s a better option: you can format any XAML document right from the Visual Studio in a single click.

    FormalXAMLDocument

    Of course, the formatting style is configurable, you can easily tweak it according to your own preference.

    XAMLFormattingOptions

    Break Apart/LineUp Attributes

    One of the most useful XAML Formatting features allowing you to break apart or line-up attributes is available separately.

    XAMLBreakApartAttributes


    Refactorings

    Import Type/All Types

    From time to time we all need to reuse some code or markup from the Internet or from older projects. With the CodeRush for Roslyn, you can paste a piece of markup into your file and make it work with a single call to Import All Types refactoring.

    Optimize Namespace References

    The best code not only works flawlessly, but also looks great. Namespace References is the very first section in every code file and often it leaves space for improvement. The Optimize Namespace References refactoring can make it perfect in a single click: it automatically sorts references and removes the unused ones.

    Convert Nested Element to Attribute/Attribute to Nested Element

    Using these refactorings, you can extract an attribute from a XAML tag and make it a child element. You can also perform the reverse operation — inline a child element as an attribute of the parent tag. This refactoring can increase XAML readability when there are excessive attributes or when the nesting level gets too deep.

    XAMLConvertNestedElementToAttribute


    Visualization Features

    Show Color

    Computers and humans understand colors differently and in most cases a computer can show colors the way we used to them. But in software development we still have to speak with the computer in its language.

    To change this state of affairs, we have the Show Color feature that adds a color preview to all colors you use in code.

    XAMLShowColor

    You can even edit a color visually by clicking any preview stripe.

    CodeRushColorPicker

    Structural Highlighting

    Structure is an essential part of all XML-based languages, and sometimes the formatting is not enough to see the structure clearly. Structural highlighting draws lines to aid visualization of this hierarchy.

    XAMLStructuralHighlighting

    Region Painting

    And we make regions look awesome!

    XAMLRegionPainting


    Markup Creation Assistance

    Selection Embedding

    Surround something with a tag or region in a single click. You can even use Ctrl+W (Selection Expand) to select the whole block from its opening or closing tag.

    XAMLSelectionEmbedding

    Paste Vector Drawing as XAML

    Imagine you have a vector drawing which you want to use in your app. For instance, you have it in Adobe® Illustrator®. With CodeRush for Roslyn, you can copy the drawing (or part of it) and paste it right into a XAML file.

    Select the required pieces and copy them to the clipboard.

    XAMLCopyFromBlend

    Then switch to Visual Studio and paste the clipboard contents into a XAML file. The drawing will be pasted in a vector format ready for you to scale and modify it as you need.

    XAMLPasteVectorIntoStudio

    We support Microsoft® Visio®, Microsoft® PowerPoint® and Adobe® Illustrator®, but other vector editors also have a good chance to work.

    Smart Duplicate Line

    Use Shift+Enter to duplicate the current line. The Smart Duplicate Line feature watches and learns from your changes to improve the duplicate line experience, creating text fields for the parts of the line we expect you to change, and automatically incrementing numeric values if we detect an incrementing pattern.

    XAMLSmartDuplicateLine

  • CodeRush for Roslyn: ForEach to Linq

    One really useful Refactoring provided by CodeRush for Roslyn is “ForEach to Linq

    This refactoring is available whenever you have a ForEach that is iterating over a master list and attempting to select either a subset, or a single item, from that list.

    Consider this legacy code example, where we have a list of orders and we want to extract a list of those orders which need Next-Day delivery.

    ExtractPriorityOrdersForEach

    Obviously that is fairly excessive. It’s also fairly complex to read.

    • There is a result set being prepared.
    • There is iteration over an incoming source set.
    • There is a condition being evaluated for each item in the source set.
    • There is the fact that passing items are being added to this result set.
    • Finally there is the returning of this result set at the end of the method.

    So naturally we want to make this easier for you.

    ForEach To Linq

    So if you position your caret immediately left of the foreach, you will be able to select ForEach to Linq (Preview below)

    ExtractPriorityOrdersForEachPreview

    Once selected, this refactoring will reduce your unsightly loop to a simple LINQ Query.

    ExtractPriorityOrdersPost

    After this it’s pretty simple to reduce this to a single simple call.

    ExtractPriorityOrdersForEachReduced

    I think we can all agree that this is much easier on the eyes and on the brain as well.

    Everything has been reduced to a simple LINQ query.

    Depending on your needs you could change this function to return an IEnumerable<Order> and strip the ToList() off the end of the expression.
    At that point you may even decide that the function, which previously hid your complexity, is now no longer necessary at all, and you can Inline and Delete this method.

    Another example is with the following type of legacy search code:
    Here we iterate over a list searching for the first item to match, in this case, on the basis of a name.

    FindCustomerByNameForEachPre

    The ForEach to Linq refactoring is again available from the foreach keyword.

    FindCustomerByNameForEachPreview

    Acceptance quickly removes the complexity of the original loop, replacing it with a simple Linq query.

    FindCustomerByNameForEachPost

    A quick Inline Temp later and the previously overly complex iteration and select, together with it’s Result variable has been completely eliminated in favour of a single statement which

    FindCustomerByNameForEachTidy

    In both of these examples, CodeRush has reduced the complexity of your code, helping you to replace old world manual loops with a concise expression of the results you want.

    These are just a few of the ways that CodeRush for Roslyn can simplify your life.

    If you don’t already have your copy of CodeRush for Roslyn, hop along to https://www.devexpress.com/products/coderush/ and pick up your free 30 day trial.
    The paid version of CodeRush for Roslyn can be had for as little as $49. That is amazing value.

  • CodeRush for Roslyn – Writing Tests Fast

    So we’ve proved that CodeRush has the fastest .Net Test runner.

    Next up I’m going to show you that CodeRush is also the quickest way to write tests.

    Note: For the purposes of this post I’m going to assume that you’ve enabled Templates, and that you are using the Spacebar to trigger their expansion.
    If you have not enabled Templates, you can use the setup wizard to do so now.

    Writing Tests using CodeRush Templates

    So how simple could it possibly be to start writing a new test?

    How about t<space> ?

    That’s only 2 keys!

    Don’t believe me? Ok try this

    • Create a class library and add a reference to your favourite testing framework. I’m going to use NUnit which I’ve added via nuget.
    • Create a new class file and delete everything in it (Keep the namespace if you want.)
    • Choose an empty line and type the letter ‘t’ and then press the spacebar.

    You’ll be presented with a new test fixture with the skeleton of a new test.
    The name of the Test Fixture is already selected.

    • Change the name of the fixture to whatever you like.
    • Hit [enter] to confirm when you’re happy.

    Your selection moves to the name of the test.

    • Change that to whatever makes the most sense to you.
    • Hit [Enter] to confirm once again.

    Your caret is repositioned once again within the body of the test that you’ve just created.

    This is roughly what you can expect this experience to be like.

     CRR_Testing_TestWithFixture

    Effort

    If you count the characters I typed (t, [space], M, y, T, e, s, t, S, u, i, t, e, [Enter], M, y, F, i, r, s, t, T, e, s, t, [Enter]) You’ll come to 26 characters.

    However 22 of those were the names of my fixture and test, (which we’d have to type no matter what) so really we’re only talking about 4 characters. 2 to generate the frame of the test (and the fixture) and another 2 to confirm we’re happy with what we’ve typed and to move on to the next bit of defining our test.

    Whichever way you look at it…. That’s not a lot of effort.

    Complexity

    How easy or hard was that? Could you do it again? What do we have to remember?

    Well we have to remember that the test template is triggered with t and then [space] (or tab if you’ve got your preferences set that way).

    That’s literally it.

    Context

    Things get even simpler when you realise that you don’t always have to learn new template shortcuts for new purposes. CodeRush’s templates are context-sensitive. Which means that the same trigger can yield different expansions under different circumstances giving you even less to learn.

    For example, if you invoke the t<space> template from within a test fixture, CodeRush spots that you already have the fixture and only generates a new test.

    CRR_Testing_TestWithoutFixture

    Assertions

    Ok well that was simple. What else can we do?

    Well what do you need to do in a test when you get right down to it?

    • You setup a scenario.
    • You assert something about the scenario.

    Well your setup will be specific to your needs, but assertions are mostly the same.

    So does CodeRush have some tricks to help us assert a little quicker? …  Of course it does Smile

    So what sort of things do we typically assert?

    Well assertions (and therefore Tests) are all about checking something that should a certain way, and failing  (ie getting the developer’s attention) if that turns out not to be the case.

    We assert equality and inequality

    You Want To Template You Use Result
    Assert Equality ae<space>
    Assert Same as<space>
    Assert Not Same ans<space>

    …we assert that things are true and false

    You Want To Template You Use Result
    Assert True at<space>
    Assert False af<space>

    …and we compare with null

    You Want To Template You Use Result
    Assert Null an<space>
    Assert Not Null ann<space>

    As you can see CodeRush has you covered and always with a template that is intuitive and easy to remember.

    I’m sure you’re starting to see the benefits of CodeRush templates. I’ll leave you there for now, and let these templates soak in. Just know that no CodeRush templates are hard wired. They can all be altered or tweaked to your needs, and you can even create your own… We’ll explore how to do that in a future post.

    Get CodeRush for Roslyn Today

    If you’d like to try out CodeRush for Roslyn, a 30 day trial can be found here on the Visual Studio Gallery.

    CodeRush for Roslyn can be yours for as little as $49

  • CodeRush for Roslyn – Setup Wizard

    Everyone is different. Everyone has their own preferences and their own approach.

    If you’ve never used CodeRush before (or even if you have) its a good idea to use our new setup wizard to configure things at a high level, before diving into your next coding session.

    The wizard will give you the chance to set base settings for several of our main features, so that they behave the way you’d like them to. There is no requirement to use the wizard, but we feel that doing so will improve your CodeRush experience greatly.

    So what can you configure using the wizard?

    Structural Highlighting

    CRRSetupWizardStructuralHighlightingWhat is it?
    Structural highlighting is where CodeRush lines are drawn between the start and end of various different types of block. This helps make sense of what is commonly called arrow code (Code which is heavily nested in successive blocks of different type). By using different colors to show the the blocks of ‘properties’, ‘accessors’, ‘foreach loops’, ‘conditional blocks’, ‘switch statements’ and ‘exception handling blocks’, CodeRush makes it much easier to determine very quickly where each of these start and end.

    What can I configure?
    The wizard options here are simple: Would you like Structural highlighting on, or off?

    What if I need more?
    The ‘Editor\Painting\Structural Highlighting’ section of our options screen (Ctrl+Alt+Shift+O) will let you change which block types are linked, their color and style.

    Numeric Keypad Bindings

    CRRSetupWizardNumericKeypadWhat is it?
    Put simply this option causes CodeRush to assign a few additional shortcuts to the keys of your numeric keypad. This keypad goes unused by the majority of people and this option will reclaim several of it’s keys for quick access to some of our more popular functions.

    Which shortcuts will be added?
    Num-Plus - Selection Increase - Increase your code selection in logical block rather than character by character.
    Num-Minus - Selection Decrease - Reverse the effects of ‘Selection Increase’ by similar logical blocks.
    Num-Period – Jump to Menu –  Our general purpose go-to navigation menu (Full details here)
    Num-Enter – Jump to Symbol – Our Symbol-specific navigation menu (Full details here)
    Num-Zero – Code / Refactor Menu – The ever popular CodeRush/Refactor key. Quick access to all the Refactorings and CodeProviders suited to your current context.

    These shortcuts involve fewer keystrokes than their default equivalents. They are also typically easier to hit given their increased size and useful location.

    Spell Checker

    CRRSetupWizardSpellCheckerWhat is it?
    As you might expect, CodeRush’s Spell Checker is the simple ability to check the spelling of certain specified parts of your document. It is disabled by default but can be enabled from the wizard in any of 3 ways.

    What can be checked?
    This screen lets you enable spell checking for 3 distinct parts of your code: Comments, Strings and API-level Members and Identifiers.
    (For our purposes, API-Level members and identifiers are those that are public, protected or internal )

    What if I need more?
    These settings can be tweaked and fine-tuned on our options screen (Ctrl+Alt+Shift+O) within the ‘Editor\Spell Checker’ page.
    From here you can specify more locations to check, filter others out and specify the dictionary you’d like to use.

    Tab to Next Reference

    CRRSetupWizardTabToNextReferenceWhat is it?
    Tab to Next Reference is the ability to place your caret within an identifier (method, variable, method) and hit Tab to initiate navigation between all the references to that identifier. I find this one as least as useful as the built in Go To Definition (F12)

    Any other associated shortcuts?
    Yes. Shift+Tab will carry you back through your references in the reverse direction, and once you are finished navigating through the references, you can hit Esc (or Alt+End) to return directly to your start point via a hidden marker.

    This has to be one of the the easiest way to navigate through your code.

    Smart Semi-Colon

    CRRSetupWizardSmartSemiColonWhat is it?
    Intelligently repositions your caret when you hit the semi-colon key, so that the semi-colon is emitted in the most sensible location.

    Why would I need that though?
    Consider features like the auto-completion of braces and parenthesis. These features are great because they finish what you start, so that you don’t have to. They leave your caret where it is, enabling you to continue working on your inner code.
    A few method calls later, and you are potentially buried in parenthesis. Smart semi-colon is a simple but effective feature which allows you to hit the semi-colon without digging yourself out from under the parenthesis mountain first.

    CodeRush will determine where the semi-colon should go, and position your caret there first before emitting the character.

    One Key Selection Embeddings

    CRRSetupWizardOneKeySelectionEmbeddingWhat is it?
    Selection Embeddings are best described as CodeRush Templates that envelop your selected code.
    A One-Key Selection Embedding is one which is triggered by the pressing of a single key. You select your code and then hit a trigger key. Instead of replacing the selected code with the key, the code is wrapped in text according to which embedding was invoked.

    CodeRush provides several out of the box.

    C – Wrap code in Try..Catch
    F – Wrap code in Try…Finally
    T – Wrap code in Try…Catch…Finally
    B
    – Wrap code in a set of braces. { … }

     Code Template Expansion

    CRRSetupWizardTemplateExpansionWhat are CodeRush Templates?
    Often described as VS snippets on steroids, CodeRush Templates are short sequences of characters which generate more verbose text within the editor. Templates can be used to create methods, classes enumerations, block constructs, unit tests, test assertions and much more.

    What can I configure?
    On this page of the wizard, you’ll decide how Templates will be triggered.

    Personally I like to pick the Space key for maximum speed and ease of activation (After all that space bar is nice and big and easy to hit). Others pick the Tab key in order to reduce the risk of accidental template expansion. You can also elect to disable the template system from this page.

     

    Markers

    CRRSetupWizardMarkersWhat are Markers?
    Markers are your virtual breadcrumbs. They are like stack based transient bookmarks in your code.

    Why would I need another kind of bookmark?
    So your coding along. Everything is going well, when you realise that you need to check something. Drop a marker. (Alt+Home) to mark your place and go investigate whatever you feel like. When your done, hit a single key (Esc or Alt+End) and return not just to when you were previously, but to the exact frame of reference you had before.

    Markers stack, which means you can drop as many as you like digging deeper and deeper into your code. When you’re ready, you collect them in reverse order (just like virtual breadcrumbs) leading you back to where you started.

    CodeRush will drop additional markers when you navigate away from where you are. Go To Definition (F12), Go To Symbol (Ctrl+Shift+Q or Num+Enter) or Jump To (Ctrl+Alt+N) will all drop markers allowing you to navigate away to investigate something and then hit Esc to return once you’re done.

    What can I configure?
    On this page you can decide if you’re like to enable Markers and further which shortcut you’d like to use to collect them.

    Note: Since VS2013, Visual Studio has altered it’s behaviour when navigating. Following jumping to an identifier’s declaration (F12), Visual studio selects the name at that declaration assuming that you want to do something with its name. This means that those have grown used to using Esc to collect markers have had to press Esc once to remove the selection and once more to collect the marker. You can opt to let CodeRush work around this behaviour by choosing the last option on this page of the wizard. 

    We highly recommend choosing the final option for your marker configuration in order to make your navigation experience as smooth as possible.

    IntelliRush

    CRRSetupWizardIntelliRushWhat is it?
    IntelliRush is the CodeRush version of IntelliSense.
    It does every thing normal intellisense does, and more.

    What extras do I get with IntelliRush?
    You can Resize IntelliRush. Just grab the edge and expand your view.

    You can filter content by member type: Restrict content to only Events, Properties or Extension methods (or something else) to quickly find the exact member you’re after.

    You can filter content by hierarchy: Restrict content to a specific level of the hierarchy. Show only members declared on the class of the object being inspected, or choose another ancestor and show only members declared on that ancestor.

    All filtering achievable using simple on-screen keystrokes whilst losing none of the power of intellisense.
     

    Menu

    CRRSetupWizardMenu

    The preferences you set in the Setup wizard are not permanent. You can return to the Wizard and change any of your choices at any time. Just open the ‘CodeRush’ menu and choose the ‘Setup Wizard’ option to begin amending your choices.

    The choices you make within the wizard have been chosen to get you up and running as quickly as possible. However there is a lot more customization available via our main Options screen also available from the ‘CodeRush’ menu or via the Ctrl+Shift+Alt+O shortcut.

     

     

     

    Everyone is different and we all have our own preferences and approach. It is our hope that the minimal amount of configuration requested by our Setup Wizard, will greatly improve your CodeRush experience.

    CodeRush for Roslyn is now available for as little as $50 a seat and a 30 day trial can be found in the Visual Studio Gallery.

  • CodeRush for Roslyn: The Fastest .Net Test Runner

    Once again it's time to benchmark the CodeRush Test Runner with the competition.

    So my last post on “CodeRush for Roslyn: Running Tests” sparked a few questions

    Like ‘Is the CodeRush test runner really that fast?’ and ‘How do other test runners stack up against CodeRush for Roslyn?’

    Test Conditions

    To reproduce this benchmark scenario, you will need:

    Software

    • 1 copy of Visual Studio 2015 – Update 3
    • 1 copy of the Nancy FX Solution, which includes 2,410 unit tests.
    • Latest versions of each test runner (I used the latest test runners available in August 2016).

    Hardware

    • I used my laptop –> Intel® Core™ i5 M 520 with 8Gb RAM.

    Test Procedure

    • Close any open instances of Visual Studio.
    • Start a fresh instance of Visual Studio with the test runner you want to benchmark already installed. Allow time to settle – see notes below.
    • Load the NancyFX solution. Allow time to settle – see notes below.
    • With the test runner you want to benchmark:
      • Run all tests. Note raw time as ‘Run 1’
      • Run all tests. Note raw time as ‘Run 2’
      • Run all tests. Note raw time as ‘Run 3’
      • Average the times from the three test runs. Enter the data in the table.
      • Make note of the number of tests detected by the test runner.
    • Close Visual Studio.
    Repeat these steps for each test runner you want to evaluate.

    Results

    We've changed competing product names so we don't unduly upset anybody.

    Here are the total times for each Test Runner on the Nancy FX Solution (lower is better):



    Here's our test run data, in table format:

    Notes:

    1. The "Test/Sec" column is calculated by taking the total number of tests (e.g., 2,410) divided by the test run time for each test runner. 
    2. The "CodeRush Is Faster By" shows how much faster CodeRush is than the competing tool. Values in this column are calculated by taking the CodeRush Test/Sec rate (e.g., 20.1) and dividing that by the Test/Sec rate for each competing product.
    3. The "JC" product tested failed to find 263 out of all 2,410 tests, so it's not doing as much work as the other test runners. Once this issue is fixed, the benchmark numbers for the "JC" product are likely to change.
    4. We realized the "RS" product we tested was incorrectly reporting total time to run all tests (erroneously reporting that it took much more time to run the tests than it actually did). So to be fair we used a stopwatch operated by a human to time the results for this product. Results manually timed like this might be off by as much as 1-2 seconds.
    5. Both the MS product and the JC product seem to have a "discovery" phase that runs every time before a test run actually gets started. During the discovery phase, test runner UI is blocked but the IDE remains responsive. We found this discovery phase for both products took two additional minutes to discover all the tests in the Nancy FX solution. We did not include those extra two minutes in calculating the total test run time for the MS and JC products, even though you could easily argue they are part of the test run. Note that the top three test runners (CodeRush, RS & TD) do not have a discovery phase, which means these three products are able to instantly start your test run.
    In the category of number of Tests Run Per Second, CodeRush is the clear winner with an average of over 20 tests (in the Nancy FX solution) run per second:
    The next closest competitor, RS, is only able to run 13.3 tests per second in the Nancy FX solution.

    No competitor comes close to the speed and efficiency of the CodeRush test runner.

    Summary

    Not all runners are created equally. Some are better than others.

    Features to look for in a good test runner:

    • Finds & runs 100% of your tests. At least one of the test runners we evaluated failed to find all the tests.
    • Finds your tests quickly. Two of the test runners we evaluated locked up test runner for an apparent "discovery phase" that lasted almost two minutes before the tests were actually run.
    • Collect test results as quickly as possible.

    No matter how you slice those numbers, CodeRush for Roslyn is still the Fastest Test runner for .NET development.

    Not convinced? Try it yourself. Download CodeRush for Roslyn and see just how much faster CodeRush is than your current test runner.

    And one last thing…. Check out the price. CodeRush for Roslyn can be yours for only $49, and CodeRush is so much more than just a test runner.

  • CodeRush for Roslyn: Running Tests

    CodeRush for Roslyn is RTM!

    That’s right CodeRush for Roslyn is out of preview and available. With it we are shipping the best ever version of our test runner.

    It’s the fastest, it’s the simplest, and it supports all the major testing frameworks (NUnit, XUnit, MSpec and VSUnit) out of the box.

    Inline Tests

    This test runner really is the simplest. With CodeRush you can run your tests direct from the editor.

    • Locate any Test

    CRRTestingExampleTest

    • Place your caret within it.
    • Run your test with Ctrl+T, Ctrl+R. (Test –> Run)

    When Run, this test passes and changes its icon to reflect its new state.

    CRRTestingExampleTest

    Naturally enough some tests do not pass. When a test fails, its Test Icon changes to indicate this, and the failing assertion is accentuated with a red background.

    CRRTestRunnerFailingTest

    More information can be found about the nature of the error if you hover the mouse over the Test Icon

    CRRTestRunnerFailingTestWithHover

    You can of course run multiple tests at once.

    The keystrokes you use depend on the breadth of tests you wish to run.

    For all tests in the Current File, use Ctrl+T, Ctrl+F. (Test –> File)
    For all tests in the Current Class, use Ctrl+T, Ctrl+C. (Test –> Class)
    For all tests in the Current Project, use Ctrl+T, Ctrl+P. (Test –> Project)
    For all tests in the Solution, use Ctrl+T, Ctrl+S. (Test –> Solution)

    Debugging a Test

    Sometimes running a test is not enough. In some cases it can be very useful to debug directly into a test.

    In this case you should:

    • Locate the Test
    • Place your caret within it
    • Press  Ctrl+T, Ctrl+D. (Test –> Debug)

    When invoked this way, the Test will be run with the debugger attached. You’ll be able to stop on break points and use watch windows in all the usual ways. This allows you to setup a test for a particular situation and then observe exactly how your code behaves in that scenario. Literally your code under lab conditions.

    Alternatively you can click the Test Icon to reveal the test context menu.

    CRRTestingInlineMenu

    Naturally you can Run test and Debug test from this menu. You can also locate the Go to runner to locate the current test within the Test Runner (see the next section for details on the Test Runner) or Run Test with Coverage.

    A full description of Code Coverage is a topic for another post, but the short version is that CodeRush will track which lines of your code are executed when a test is run. This can give you a quick estimate of which parts of your code might require additional testing.

    The last item is Add to Session. I’ll leave that one for a minute or two whilst we discuss the Test Runner.

    Test Runner

    This is the CodeRush TestRunner. Shown here with some of the Unit Tests within NancyFX

    CRRTestRunnerNancyTests

    You can launch the Test Runner in 3 ways.

    • From the Context menu of a test or test fixture. (Go to runner)
    • From the Main CodeRush menu (CodeRush | Test | Test Runner)
    • Using the universal Test Runner Shortcut (Ctrl + T, Ctrl+T)

    The default view of the Test Runner will show you all the projects containing tests and the counts of tests within those projects.

    All the standard options are available from within the Test Runner. From left to right we have ‘Run Selected Tests’, ‘Run All Tests’, ‘Debug Selected Tests’. Naturally enough we follow that with the ability to ‘Run Selected Tests with Coverage’ and ‘Run All Tests with Coverage

    When you run your tests, the number in the brackets of each node expands to show not just the total, but the number of passing and failing tests within that node.

    CRRTestRunnerNancyTestsRun

    If you turn on the ‘Show Duration’ option CRRTestRunnerToolbarShowDuration you can also see how long any given node (single test or group) took to execute.

    CRRTestRunnerNancyTestsRunDuration

    At all times the status bar will track the number of the total number of tests, how many of them are currently Pass or Fail and how many are currently designated Ignored or Explicit.

    CRRTestRunnerStatusBarNancyFX

    Grouping and Filtering

    Your tests can be grouped by Project, Namespace, Category, File Path or just as a Flat List.

    CRRTestRunnerGroupingDropdown

    You can show any combination of Not Run, Passed, Failed, Ignored or Explicit tests using the toolbar toggles.

    CRRTestRunnerFilterToggles

    Having determined the selection of tests you’re interested in, you can run any of those remaining visible through the use of the right click menu or the previously mentioned icons on the toolbar. This context menu is as for an individual test in the editor, but will now apply to all nodes within the one you right-click. This allows you run all tests in a namespace, project or category at the click of a button.

    If you’re looking for a particular test, but aren’t sure where it is, than the test search box is your friend. As you might expect, enter some search text, hit enter and CodeRush will find any test that matches all your criteria (Filter Toggles, and Search)

    CRRTestRunnerToolbarSearch

     

    How Fast is the CodeRush Test Runner?

    So the single simplest test is to instruct CodeRush to run all the tests in the Solution. Since I had the NancyFX solution loaded, I simply hit Ctrl+T, Ctrl+S and CodeRush located and ran the 2410 tests present.

    Obviously I needed something to compare this with, so I also took a well known Brand ‘X’ test runner for a spin and these are the results I got.

    Test Runner Test Execution Time
    Brand ‘X’ 182s
    CodeRush (Default settings) 143s
    CodeRush (All Cores) 128s

    So just using the default settings, CodeRush’s test runner is 39 seconds (22.5%) faster than the Brand ‘X’ test runner.

    But you’ll notice that there is another entry for CodeRush. When CodeRush is allowed to use all my processor’s cores, it gets even quicker, eventually toping out (on my machine) at a little over 54 seconds (30%) faster than the Brand ‘X’ test runner.

    Sessions

    So you’ll recall a few sections back I hinted at a new CodeRush test runner feature.

    The CodeRush test runner, like all other test runners has long supported the idea of running either a single test or a set of tests defined by a class, file, project or indeed the entire solution.

    However you don’t always, especially in legacy projects, have the convenience of having all appropriate tests in a single namespace or project where you need them. This wouldn’t necessarily be an issue if there weren’t those strange group of tests written in a dark corner which take an excessively long time to run. Then there’s that other set that you’ve been told not to run because no-one is quite sure that they don’t have side effects.

    Then there are the tests that you really do want to run. They should all exist in the same place, but for some unearthly reason they have been defined in a number of strange disparate locations in several different projects. You will of course bring these tests together in some carefully crafted namespaces in just one or 2 projects in good time, but right now is not the time. They work well. they are essential to the stability of the project. But they are disparate and a pain to use.

    Enter ‘CodeRush Testing Sessions’

    A CodeRush Testing Session is a very simple thing. (Well all the best things are aren’t they.) A Session is a named ad-hoc selection of tests. Nothing more. No need to alter code to add categories. Just pick the tests you care about, and start to work with them. Of course the real key with sessions is in how you use them.

    To create a new session…

    Just visit the context menu of any test (or group of tests) and choose Add to Session | Create New Session. Your chosen tests are added to a new session with the name “Session 1” or similar. The Test runner has a new Tab named for the Session you’ve created, containing only those tests that you added. Feel free to add more tests to the Session. As many (or as few) as you want.

    To name a session

    Simply double-click the name of the session, and you’ll be able to name it whatever you like. I like to use ‘WIP’ (Work in Progress) to house those tests that are useful to me in my current situation.

    To add more tests to a session

    Pick Add to Session | Add to WIP Session from the Test (or Test Fixture) context menu, either from an appropriate node in the Test Runner, or from within the editor itself.

    To use a session…

    Simply use the same standard buttons as you do when there are no active session. ‘Run All Tests’ and ‘Run All Tests with Coverage’ now run within the confines of your active Session. Naturally because the Test Runner hides tests (and fixtures) which aren’t in your current session, it’s far simpler to find the results you’re after.

    To switch between sessions…

    It shouldn’t really come as much of a surprise, that you can have multiple sessions on the go at the same time. Each time you create one, a new tab is added to represent the tests you added to it.

    You can have Sessions for:

    • Those tests you need to run every few minutes, to check you’re not breaking some part of the subsystem you’re working on.
    • All the tests in your solution except those few slow tests you try to avoid running unless absolutely necessary.
    • Those slow tests you’ve been avoiding, but which need to run every now and again, because slow or not, you do need them.

    There are no rules. You could pick 3 tests from one project, all the tests from a 2nd project and 6 tests from 6 different test fixtures in a 3rd project.

    This is a great feature for use when you know you have a need to run 2 or 3 tests (or sets of tests) which are related by something other than the standard mechanisms. I personally like to create 3 sessions ‘WIP’ (Work in Progress), ‘All but Slow’ and ‘Slow Tests’, but feel free to use sessions for anything you like.

    So how do you switch between session? Simple: Just select the tab which represents the session when you want to work with.

    Oh and one last thing: CodeRush Test Sessions will persist between VS sessions. Which means they will survive the closing and re-opening of both your solution and studio, allowing you to setup exactly the sessions you need, safe in the knowledge that you won’t have to rebuild them in your next coding session.

    Testing is fast, fun and easy again. So go out there and build some rock solid and fully tested code.

    CodeRush for Roslyn – Free to try. Only $49 to buy! (Includes a year of free updates)

  • CodeRush for Roslyn: The Navigation Menu

    Every symbol in your code has significance. Every symbol is a jumping off point for all sorts of investigation.

    Typically you’ll be used to being able to see “All References” to a variable or class, and determine exactly how heavily used it is within your code.

    This is a great way to get a general feel for where your code is used within your project\solution, but what happens if you need to ask some more specific questions? What if you wanted to find something more focused than “every reference” to your chosen symbol?

    Enter the Navigation Menu

    The Navigation menu (AKA the JumpTo menu) is your one stop shop for all sorts of navigation goodies.

    Place your caret on any symbol in your code and hit Ctrl+Alt+N (or Num Decimal if you’ve enabled numeric keypad bindings)

    NavigateFromClassReference

    I’ve chosen to place my caret on an instantiation of a StringBuilder in the source of OpenLiveWriter. As a result I’m being offered the choice of locating related Base Types, Declaration, Derived Types, Instantiations, Parent Types and more.

    All I have to do to choose one of these options, is highlight one (using Arrow keys) and select it (using Enter).

    Once selected, the Navigation menu will delegate to the appropriate NavigationProvider, which will then list all of the qualifying code elements.

    In my case I’ve chosen ‘Instantiations’ because I’m interested in finding a particular piece of code I was looking at earlier which I know created a StringBuilder.

    When I pick ‘Instantiations’ from the list I get the following window:

    InstantiationsOfStringBuilder

    It looks like OpenLiveWriter uses quite a few StringBuilders within it’s code. However I remember that the code I was looking at, created it’s StringBuilder using the length of a buffer as a parameter.

    So I type ‘buffer’ into the search window at the top of the list, and CodeRush narrows it’s list down from over 100 items, to only 6.

    InstantiationsOfStringBuilderFilteredByBuffer

    From here it was very easy to locate the code I was looking for. Once I found the correct entry, I simply hit [Enter]  and CodeRush positioned me right where I wanted to be.

    Navigation Providers

    As you can see from our worked example, the Navigation menu can be very useful. However I’ve only scratched the surface. I worked through an example with the instantiations entry which, as you saw, provides a list of places where your chosen symbol is instantiated.

    However if you recall the Navigation menu offered me 7 other choices to help us navigate to the code of our choice.

    The last 2 of these are fixed items. Symbols and Files will take us to the Quick Nav and Quick File Nav features respectively.

    The others are Navigation Providers each dedicated to locating a specific type of related code.

    At the time of writing there are 11 NavigationProviders and counting. Each dedicated to a specific type of code relationship. The reason we only saw 6 of them in the previous example is that they are context sensitive. They only appear when appropriate.

    They are:

    • Declaration
    • Base Types
    • Derived Types
    • Parent Type
    • Members
    • Overridden Members
    • Instantiations
    • Implementations
    • Assignments
    • Overloads
    • Overrides

    While all of these providers are useful, I feel it’s worth drawing attention to a few of them in particular.

    Firstly the Assignments provider. How often have you wondered about all the places in your code where a field is altered? The Assignments navigation provider will let you locate all the statements that assign a value to your chosen symbol.

    The Base Types provider will provide you with a list, not just of immediate base types, but of the entire ancestral hierarchy of your nominated type, including interfaces.

    The Implementations provider is particularly useful.
    You can use this one on references to interfaces or abstract classes
    Place your caret on the reference to the interface and ask to see all implementations. Immediately you’ll be presented with a list of classes which implement the interface in question.

    Ordinarily you might think to use the “All References” functionality to locate these classes. However the All References feature does exactly what it says. It returns ALL references and sometimes this can be a bit excessive. For example: Users of VB.net will be used to asking for All References to a given interface, and then having to deal with more results than they might want to. This is because the default interface implementation technique is explicit. As such the name of the interface is mentioned (and thus creates a ‘reference’) for each and every member in that interface. Implementations makes this a non-issue.

    You can also use it on references to interfaces or abstract members
    Imagine you have a variable of type IFoo and are calling it’s Bar method. If you place your caret on the call to Bar and invoke the Implementations Navigation provider, you’ll be provided with a list of every class that implements IFoo and more specifically, the methods that implement IFoo.Bar. You’ll then be able to navigate directly to any one of them.

    Options

    Naturally each Navigation Provider has it’s own custom set of options. These are typically used to filter the available list of items: Source Code vs Meta, Open Files vs All Files

    Just tap Ctrl to reveal the options for any given Navigation provider

    The Navigation Menu is so full of functionality that it’s starting to become the first place I go for almost any form of navigation. I highly recommend you check it out, whatever you’re looking for.

    Can you think of an additional Navigation Provider you’d like to see? Let us know in the comments and we’ll see what we can do to help.

    Oh and one more thing

    The NavigationProvider user interface leaves things simple in the interests of speed. If at any point you’d like to examine the hierarchy of your result set, you can transfer it to the References interface in a new tab by pressing Ctrl+P or clicking the icon in the upper right of the NavigationProvider. Since the References tool window can host multiple tabs, you can maintain several lists of interest at the same time.

    So if you’ve not already got your copy of CodeRush for Roslyn, head on over to the visual studio gallery and grab a copy of our preview now

  • CodeRush for Roslyn: The References Toolwindow

    The CodeRush References tool window is a wonderful thing.

    Place your caret on a symbol and press Shift+F12 asking the question: “Where else is this used?”.
    Next: Navigate the results with the Arrow Keys and Hit Enter to visit the selected reference.

    Consider an example search for all the references to LightweightControlCollection in OpenLiveWriter:

    The VS version of this is ok, but it’s very black and white and isn’t exactly very configurable. 50% of the screenshot below is taken up with the name of the file the code was found in.

    image

    Compare this with CodeRush version and I think you’ll agree, we improved things a lot.

    A Brighter Outlook

    The first thing you’ll notice about CodeRush’s presentation is the introduction of color. In the image below I have stripped away all the hierarchical feature of CodeRush. Even without all of that useful information, you’ll note that it is still easy to pick out XML Doc comments from class declarations, instantiations and constructors. These days we code in color because it helps us discern additional information about the code and the way the compiler sees it. Why should our search be limited to just black and white?

    image

    Hierarchy

    Despite the addition of color, there is still a lot of information to absorb in a list like this. Wouldn’t it be better if we could group the information in some sensible way?

    Well CodeRush has you covered there as well. These 5 toolbar buttons imageallow you to specify which levels to group your references by. From left to right they are: Project, File, Namespace, Type and Member. They can all be toggled independently and provide additional collapsible parent nodes for your results.

    ReferencesWithProjectAndType

    You have complete control over the level of hierarchy you use. See above how I have chosen to use Project and Type nodes in my hierarchy. This immediately expands the amount of horizontal space allocated to the code, rather than the naming of the file in which it sits. Just take a moment to compare this image with the first one.

    Preview

    You can also elect to view a preview of the location of the selected item. Use the following icons image to select between a preview on the right of your results, one beneath or no preview.

    ReferencesWithPreview

    Filter by Usage

    The icons next to each result reflect the type of usage. Either Reads, Writes or New Instances. If you so choose, you can filter your results by the type of their usage. The drop down box in the toolbar will allow you to filter by ‘Reads’, ‘Writes’, ‘New Instances’, or ‘All Usages

    image

    See how the ‘New Instances’ choice reduces my previous list to only 2 entries.

    ReferencesFilteredByNewInstances

    Filter by Text

    You may also filter the items in your results by text. Text entered in the Search box image will cause CodeRush to remove all items that do not contain that text within their entry. See below how I have filtered by the word ‘index’ and removed all but those with this text present.

    image

    Refresh and New Search

    There are 2 final icons that should be explained. image

    The first of these is Refresh. The entries in the References tool window do not update as you alter code. They reflect the state of the code at the moment you engaged the feature. Pressing the Refresh button will execute the original search update the results in the current Tab.

    The second icon is New Search. When pressed, it will leave the existing results in place, and create a new Tab based on the original search criteria. This means that in the new Tab, the Usages drop down will be reset to ‘All Usages’ and the ‘Search’ box will be cleared.

    Each new activation of the References tool window via the Shift+F12 key will cause an additional Tab to be created, allowing you to keep many sets of results active at once.

    The References ToolWindow has never been better. It’s fast, clear and colorful in a meaningful way. With the ability to filter it’s results as well as arranging those results with the hierarchical elements you choose.

    If you’ve not already got your copy of CodeRush, you can find a preview here on the Visual Studio Gallery

  • CodeRush for Roslyn: Quick File Nav

    Quick File Nav is the fastest way to locate any file in your solution. All you need to know is part of the name of the file you’re looking for.

    Usage

    The default shortcut for Quick File Nav is Ctrl+Alt+F. Once triggered, you’ll see the following screen:

    image

    [Tip: If you’d prefer to use another shortcut, you can customize this in the Options dialog (Ctrl+Shift+Alt+O) on the shortcuts page (IDE\Shortcuts) in the Navigation section.

    If you begin to type the name of a file, then the list will be filtered to show only those items whose name contains the characters you type.

    Let’s suppose you have been working in the OpenLiveWriter solution, and that this time you are looking for a File whose name contains the word ‘Helper’. See below how I have typed the word ‘Helper’ into the search box. CodeRush Immediately locates those files with the word ‘Helper’ in their names.

    image

    See once again, how all the pertinent details are provided. Each file’s Name is accompanied by it’s Project and File Type. If a file does not reside in the root of it’s project, then the Folder name also provided. Your search term (In this case ‘Helper’) is highlighted within each item, indicating which part of the item qualified it to be in the list.

    You can use the Arrow keys to navigate through the items presented in the list. Once you’ve found the item you require, press Enter and the file will be opened for you in the editor.

    Camel Case Searching

    Imagine I need to find one or more files whose name Starts ‘CommandLine’. Well I could certainly type all 11 characters, but I could also use Camel Case Searching to help ease things. By typing just ‘CL’ in upper case, I can instruct CodeRush to search for files whose name contains a capital ‘C’ followed (at some point) by a capital ‘L

    image

    See how the first couple of entries shown, are ones which contain the capital letters ‘C’ and ‘L’ in that order, even though they may be separated by several other characters. Additionally CodeRush shows other files containing the sequence ‘cl’ just in case you were looking for any of those.

    Options

    If you tap Ctrl, you’ll reveal options allowing you to chose between displaying (A)ll files, or just those which are (O)pen.

    image

    So use Ctrl+Alt+F to launch Quick File Nav and Jump to any file in your solution instantly.

    .. and feel free to leave us your feedback to indicate how we might improve this and other features.

1
2 3 4 5 6 7 8 9 10
LIVE CHAT

Chat is one of the many ways you can contact members of the DevExpress Team.
We are available Monday-Friday between 7:30am and 4:30pm Pacific Time.

If you need additional product information, write to us at info@devexpress.com or call us at +1 (818) 844-3383

FOLLOW US

DevExpress engineers feature-complete Presentation Controls, IDE Productivity Tools, Business Application Frameworks, and Reporting Systems for Visual Studio, along with high-performance HTML JS Mobile Frameworks for developers targeting iOS, Android and Windows Phone. Whether using WPF, ASP.NET, WinForms, HTML5 or Windows 10, DevExpress tools help you build and deliver your best in the shortest time possible.

Copyright © 1998-2017 Developer Express Inc.
All trademarks or registered trademarks are property of their respective owners