locked
How to get TestCategory values inside the TestMethod at runtime? RRS feed

  • Question

  • Hi all

    I use the Visual Studio Team Test (VSTT) in VS2010 Premium Edition

    I have to set the test category before the test method just like the following, as below that I want to get the 2 TestCategory that I set and print or have some logic flow based on the TestCategory, how can I get this and put into myTestCategories as String()?

    Thanks a lot

        <TestMethod()>
        <TestCategory("FunctionType=1")>
        <TestCategory("FunctionSubType=2")>
        Public Sub TestMethod_23_StartExe_001()
            ...
            Dim myTestCategories as String() = ...
            ...
        End Sub

    Monday, April 8, 2013 4:48 AM

Answers

All replies

  • Hi TungLee,

    Glad to see you again.

    I did some research about this issue, but I didn’t find the official document about how to use it like this issue.

    As far as I know, we often add test categories to a test manually, it means that we know the categories’ value before we run the test, so if we want to use its’ value, we could define a new String with the same value.

    http://msdn.microsoft.com/en-us/library/dd286683(v=vs.100).aspx

    I know it is the solution you want to get, but you could submit the suggestions and ideas: http://visualstudio.uservoice.com/forums/121579-visual-studio. The Visual Studio product team is listening to user voice there. Thanks for your understanding.

    Best Regards,


    Jack Zhai [MSFT]
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, April 10, 2013 2:18 AM
  • Dear Jack

    "if we want to use its’ value, we could define a new String with the same value." is just the concern from the developer that prepare test method, as we have over 200 test method we plan to do and we would have 2-3 or more test category per test method, hence if we explicit add one more test properties for each test category, it would be huge effort

    total number of line to add = (# of testmethod) x (# of testcategory)

    hence my concern is the maintenance.

    Hence for my situation, what else can I do if for existing feature in VS2010

    Wednesday, April 10, 2013 6:22 AM
  • Hi TungLee,

    Actually I didn’t use it before, and one idea is that we could get the test category with the specific property. But I’m afraid that it will require the high handle-code knowledge.

    Reference:

    TestCategoryAttribute.TestCategories Property

    TestCategoryAttribute Class

    Hope it could provide useful information.

    Best Regards,


    Jack Zhai [MSFT]
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, April 10, 2013 7:27 AM
  • Dear Jack,

    Thx your prompt response!

    And do you mean we define testproperty, and to inject this as test property by code at run time?

    is it correct? (as if so, I plan to have framework to do so before the test method and it feasible for me. but I want to ask any sample code? also, if for run time injection and I have to use MSTest with /category parameter, can the runtime inject case ok so that we only execute test methods based on the category parameter?

    Best Regards

    Wednesday, April 10, 2013 7:54 AM
  • Hi TungLee,

    Glad to receive your reply. J

    Maybe I misunderstood this issue. Actually I mean that you could Create Custom Test Category Attributes in Visual Studio, since all categories are based on strings that we must type, so one idea is that you could custom test category attributes that return the proper string.

    Reference:

    http://toddmeinershagen.blogspot.com/2010/09/create-custom-test-category-attributes.html

    also, if for run time injection and I have to use MSTest with /category parameter, can the runtime inject case ok so that we only execute test methods based on the category parameter?

    Sorry for that I’m not very clearly about the above issue, but we often run the tests with TestCategory with the following options in VS2010/in the Command line.

    http://msdn.microsoft.com/en-us/library/dd286683(v=vs.100).aspx

    If I have misunderstood anything, please make free feel to let me know.

    Best Regards,


    Jack Zhai [MSFT]
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, April 10, 2013 8:22 AM