-1

I have come with a growing library of quick one-click functions that I want to call as development tools. So far, I have written them as [TestMethod, TestCategory("ToolsManagement")] functions that I set at [Ignore] and when I want to use my tool I remove the [Ignore] line and run the test.

What is a better way to organize my tools library as I am tired of seeing them as test functions?

enter image description here


Edit 1:

I'll try to explain a bit more what I need...I hope it will be clearer.

While developing, I debug and test the application, so I often insert/update data in the database. Often, I want to create a snapshot, restore a snapshot, or recreate the database so it is empty. I also coded functions to reproduce business cases, inserting a lot of data at different places for examples, instead of doing it manually. Those are example of my development tools that I want quick and easy access to, but not from the Test View.

Bruno
  • 4,685
  • 7
  • 54
  • 105
  • anyone care to explain the negative reception O_o – Bruno Jun 04 '16 at 04:04
  • You're asking a question that is open for opinion and can be a bit ambiguous. What does "better" mean? What does "organize" mean? SO is about specific questions with clear answers. This question is not going to be terribly helpful for future readers. – Enigmativity Jun 04 '16 at 04:27
  • I don't agree but okay I guess – Bruno Jun 04 '16 at 04:55
  • The lack of good quality answers and the down-votes should be enough to support what I'm saying. – Enigmativity Jun 04 '16 at 08:07
  • 1
    In order to give a good answer you really need to give a better indication of how/when these get run, or what they are for. We can't suggest good solutions without fully understanding the problem. – Richard Matheson Jun 07 '16 at 06:09
  • Sorry for downvotes you're getting, sometimes people here think on a broader way and don't just skip/ignore a badly asked question or something unhelpful for the whole world (which is the purpose of SO, I guess). By the way, care to expand/reformulate your question? I believe you're trying to achieve something we usually do as devs but I can't completely understand what it is. Anyway, as suggested by enzian, maybe a separate console application is the way to go. – ccalboni Jun 09 '16 at 11:03
  • @ccalboni Thanks for your input, I edited the question, hope it is clearer – Bruno Jun 09 '16 at 15:07

4 Answers4

5

I'd suggest you use a new Visual Studio 2015 Feature called "C# Interactive" to execute your utility functions. You can just mark them in the code and press CTRL+E,Ctrl+E to execute this method. Like this you can remove the [TestMethod] attributes all together and thus not have them show up in the VS test explorer!

Another suggestion in can give you is to bundle this code to be able to execute it from the CLI. This could help you automate tasks, have nice traces to the CLI about whats happening - It could be more convenient than executing it in VS!

enzian
  • 733
  • 5
  • 13
  • Thanks! I like this answer. I didn't know about C# Interactive, I looked a bit for it and it seems to be new in VS2015? I am using VS2012 so I guess this is not available to me for now. I also like your idea to bundle the functions in a simple cmdline application. – Bruno Jun 07 '16 at 15:36
1

I strongly suggest a separate console application containing all your jobs or, in case everything is related to your database server, one or more .sql files containing those operations (then, select what you need to run and CTRL+ALT+E to execute).

ccalboni
  • 12,120
  • 5
  • 30
  • 38
0

You can sort your tests by different types by clicking on the small icons above the run-all command. This might help you to sort and collapse the ones you aren't running. You could also pull those 'tools' out into another project in your solution so they aren't part of your Unit Tests project.

moyeradon
  • 443
  • 5
  • 13
  • Thanks, it's already what I am doing. I don't want those tools as `[TestMethod]` anymore, but I have no better idea... :\ – Bruno Jun 02 '16 at 14:15
0

The functionality you are expecting is a conditional ignore attribute. Which is not available with MS Unit Testing.

Workaround 1:

As a workaround you can use the below code snippet

[TestClass]
public class UnitTest1
{
    [TestInitialize()]
    public void Initialize() 
    {
        //Assert.Inconclusive("Message");        
    }

    [TestMethod]
    public void TestMethod1()
    {

    }

    [TestMethod]
    public void TestMethod2()
    {

    }
}

You can toggle the

//Assert.Inconclusive("Message");

and achieve your expected functionality.

Note: Since we use "[TestInitialize()]" all the test method in this TestClass will run this at first.

Workaround 2: You can make use of conditional compilation as illustrated below

[TestClass]
public class UnitTest1
{
    [TestMethod
    #if !Ignore
    , Ignore()
    #endif
    ]
    public void TestMethod1()
    {

    }

    [TestMethod
    #if !Ignore
    , Ignore()
    #endif
    ]
    public void TestMethod2()
    {

    }
}
Kesavan D
  • 184
  • 5