Unable to run the automated tests using MsTest.exe

4 posts, 0 answers
  1. S
    S avatar
    1 posts
    Member since:
    Mar 2013

    Posted 26 Oct 2017 Link to this post

    Here is the sample code

        [TestClass]
        public class UnitTest1
        {
            private Manager m_manager;

            [TestInitialize]
            public void TestInitialize()
            {
                var mySettings = new Settings { Web = { DefaultBrowser = BrowserType.Chrome } };
                m_manager = new Manager(mySettings);
                m_manager.Start();
                m_manager.LaunchNewBrowser();
            }

            [TestCleanup]
            public void TestCleanup()
            {
                m_manager.Dispose();
            }

            [TestMethod]
            public void NavigateToGoogle()
            {
                m_manager.ActiveBrowser.NavigateTo("https://google.com/");
            }
        }

    Assuming the following build to a telerick.dll

    This is the command I am using from cmd prompt

    MSTest.exe /testcontainer:"C:\POC1\Telerik\Telerik\bin\Debug\Telerik.dll"

    When I run using command I am getting the following error, it runs perfectly fine when I use VisualStudio.

              <Message>Initialization method TelerikTestingFramework.UnitTest1.TestInitialize threw exception. System.TypeInitializationException: System.TypeInitializationException: The type initializer for 'ArtOfTest.WebAii.Core.Settings' threw an exception. ---&gt; System.IO.FileNotFoundException: Could not load file or assembly 'Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The system cannot find the file specified..</Message>
              <StackTrace>    at System.ModuleHandle.ResolveType(RuntimeModule module, Int32 typeToken, IntPtr* typeInstArgs, Int32 typeInstCount, IntPtr* methodInstArgs, Int32 methodInstCount, ObjectHandleOnStack type)
       at System.ModuleHandle.ResolveTypeHandleInternal(RuntimeModule module, Int32 typeToken, RuntimeTypeHandle[] typeInstantiationContext, RuntimeTypeHandle[] methodInstantiationContext)
       at System.Reflection.RuntimeModule.ResolveType(Int32 metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments)
       at System.Reflection.CustomAttribute.FilterCustomAttributeRecord(CustomAttributeRecord caRecord, MetadataImport scope, Assembly&amp; lastAptcaOkAssembly, RuntimeModule decoratedModule, MetadataToken decoratedToken, RuntimeType attributeFilterType, Boolean mustBeInheritable, Object[] attributes, IList derivedAttributes, RuntimeType&amp; attributeType, IRuntimeMethodInfo&amp; ctor, Boolean&amp; ctorHasParameters, Boolean&amp; isVarArg)
       at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeModule decoratedModule, Int32 decoratedMetadataToken, Int32 pcaCount, RuntimeType attributeFilterType, Boolean mustBeInheritable, IList derivedAttributes, Boolean isDecoratedTargetSecurityTransparent)
       at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimePropertyInfo property, RuntimeType caType)
       at System.Reflection.RuntimePropertyInfo.GetCustomAttributes(Type attributeType, Boolean inherit)
       at ArtOfTest.WebAii.Core.Settings..cctor()
     --- End of inner exception stack trace ---
        at ArtOfTest.WebAii.Core.Settings..ctor()

     

     

  2. Nikolay Petrov
    Admin
    Nikolay Petrov avatar
    308 posts

    Posted 30 Oct 2017 Link to this post

    Hello Setti,

    Thank you for providing sample to reproduce the problem.

    If adding a Newtonsoft.Json package to the VS project it would resolve the missing dependency problem as shown on the attached screen-shot indeed.

    If running with MSTest.exe the test dll file there would be observed the reported problem. It is caused by the fact the MSTest does not copy all necessary files to the output execution directory. There could be two approached to resolving such problem:

     1. Add a deployment attribute to the test method meant for execution as the following one:
    [DeploymentItem(@"C:\[Full Path to DLL File]\Newtonsoft.Json.dll")]

     2. The other approach is to create and refer in the command line a settings file that contains dll deployment information.

    Both approaches are described here for a reference. More on MSTest command line options you could find here

    I hope those directions helps.

    Best Regards,
    Nikolay Petrov
    Progress Telerik
     
    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainings
     
  3. Lisa
    Lisa avatar
    34 posts
    Member since:
    Nov 2017

    Posted 09 Feb in reply to Nikolay Petrov Link to this post

    Hi Nikolay,

    I created a unit test project to try out the Testing Framework.

    I'm getting the error above when running from Test Explorer.

    Details: 

    Visual Studio Enterprise 2015 14.0.25431.01 Update 3

    Test Studio was last downloaded on 1/30/2018

    Nuget Package for Newtonsoft.Json 10.0.3 is installed - even with it installed I'm getting the error.

    I tried running the test with and without the DeploymentItem line for Newtonsoft and I get the error either way.

    The test class is shown partially in the screenshot attached. The test is failing before hitting the first line of the test method. 

    Result Message: Initialization method SASTestingFrameworkUnitTests.LoginUsingImpersonation.TestInitialize threw exception. System.TypeInitializationException: System.TypeInitializationException: The type initializer for 'ArtOfTest.WebAii.Core.Settings' threw an exception. ---> System.IO.FileNotFoundException: Could not load file or assembly 'Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The system cannot find the file specified..

     

     

  4. Elena Tsvetkova
    Admin
    Elena Tsvetkova avatar
    866 posts

    Posted 14 Feb Link to this post

    Hello Lisa,

    Thank you for the details. 

    To be able to run any tests in which you have used the testing framework in a unit test you will need to GAC the Newtonsoft.Json.dll 10.0.3 so that it could be located. 

    Or alternatively you could use the VStest.console.exe to run the tests. 

    Thank you for your understanding! 

    Regards,
    Elena Tsvetkova
    Progress Telerik
     
    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainings
     
Back to Top