locked
Enable Log TeamCity Unit Tests - UWP RRS feed

  • Question

  • I have a problem when I try to write in console application of TeamCity. In a Unit Test Project (classic) if I use Trace.WriteLine, TeamCity recognized that and write value in her console. Unique case when TeamCity write in her console are test Fail and I send a message, such as:

    Assert.IsTrue(false, "My message");
    

    In my project, Unit Test(Windows Universal), I try to use Trace, but this does not exist, I try to user System.Diagnostic.Debug.Writeline, but this only write in Visual Studio console when I run my tests in Debug mode.

    Someone help me to write logs, when I execute my tests in my Unit Test (Windows Universal)?

    Notes:

    • TeamCity Professional 10.0.3 (build 42434)
    • Agent: Windows 10
    • Project: Unit Test App (Windows Universal)
    • Framework Tests: MSTestFramework.Universal

    Thanks in Advance

    Thursday, December 22, 2016 2:49 PM

All replies

  • Hi fipcurren,

    According to your description, I think this is not related to TeamCity, this is related to UWP Unit test itself.

    Debug.Writeline() and Trace.WriteLine() are not working in Unit Test for UWP, because Unit Test for UWP is a .exe file. In my side, I used this two functions and noting I could get.

    But I think we could use the UWP API that help us display the test message, here is my code in Test Method:

    ToastTemplateType toastTemplate = ToastTemplateType.ToastImageAndText01;
    Windows.Data.Xml.Dom.XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(toastTemplate);
    Windows.Data.Xml.Dom.XmlNodeList toastTextElements = toastXml.GetElementsByTagName("text");
    toastTextElements[0].AppendChild(toastXml.CreateTextNode("test message"));
    ToastNotification toast = new ToastNotification(toastXml);
    ToastNotificationManager.CreateToastNotifier().Show(toast);
    

    With above code “test message” could be displayed during the test running. After running I could get this message from the right-bottom cross of my computer.

    Sincerely,

    Oscar


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Proposed as answer by Weiwei Cai Monday, December 26, 2016 9:23 AM
    • Unproposed as answer by Oscar_Wu Tuesday, December 27, 2016 1:18 AM
    Friday, December 23, 2016 5:59 AM
  • Hi @Oscarw Wu, 

    Thanks for your solution. My idea ir very very simple: in team city I need to show result test for each test in console (of teamcity), and you ask Why?

    I respond: This tests are run many times of day, and I need to save result of tests (output + result) to later I see this if something are wrong.

    If you write Console.Trace.Writeline() in Unit Test of Class Library (classic), TeamCity show output for every tests run.

    Toast notification are not good solution for me, because, the test are run from schedule and I not always in my computer :)

    I try to use Metrolog library, EventSource and others, but not with succefull.

    Thanks a lot.
    Monday, December 26, 2016 10:08 AM
  • Hi fipcurren,

    According to your description, I think there is no default API for logs you could use. But I have my own idea for your issue.

    Whether you could use IO API with C# to output logs to a txt file manually, you could implement it in [TestCleanup] method, after every TestMethod, [TestCleanup] will be run.

    Sincerely,

    Oscar


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, December 27, 2016 2:24 AM
  • Hi fipcurren,

    According to your description, I think there is no default API for logs you could use. But I have my own idea for your issue.

    Whether you could use IO API with C# to output logs to a txt file manually, you could implement it in [TestCleanup] method, after every TestMethod, [TestCleanup] will be run.

    Sincerely,

    Oscar


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Hi Oscar (@Oscarw Wu),

    UWP have a particular work. I try to save my logs with (StorageFile Api). Save in local folder of app, and when my app is shutdown, I copy the file to Installation Folder.

    Problem with this: My projeto of unit test type of "Unit Test (Universal Windows)", and when tests are finished, the local folder and installation folder of app are deleted and I say "bye-bye" to my file with logs :) 

    Another way is: Write in local project file, but UWP run in sandbox right? My access to write or create files outside Local Folder, Installation Folder and Known Folders is denied.

    I don't know what I do anymore :( 

    Thanks.





    Tuesday, December 27, 2016 9:54 AM
  • Hi my friend,

    Please refer to the following link to storage the contents:

    https://msdn.microsoft.com/library/windows/apps/br207871?f=255&MSPPError=-2147217396

    Hope it helpful for you.

    Sincerely,

    Oscar


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, December 28, 2016 9:18 AM