Unable to run the automated tests using MsTest.exe

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

    Posted 26 Oct Link to this post

    Here is the sample code

        public class UnitTest1
            private Manager m_manager;

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

            public void TestCleanup()

            public void NavigateToGoogle()

    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=, 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
    Nikolay Petrov avatar
    257 posts

    Posted 30 Oct 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
Back to Top