<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>Testing on But it works on my PC!</title>
    <link>https://blog.richardfennell.net/tags/testing/</link>
    <description>Recent content in Testing on But it works on my PC!</description>
    <image>
      <title>But it works on my PC!</title>
      <url>https://blog.richardfennell.net/images/papermod-cover.png</url>
      <link>https://blog.richardfennell.net/images/papermod-cover.png</link>
    </image>
    <generator>Hugo -- 0.147.0</generator>
    <language>en</language>
    <lastBuildDate>Wed, 21 Apr 2021 13:32:03 +0000</lastBuildDate>
    <atom:link href="https://blog.richardfennell.net/tags/testing/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>Loading drivers for cross-browser testing with Selenium</title>
      <link>https://blog.richardfennell.net/posts/loading-drivers-for-cross-browser-testing-with-selenium/</link>
      <pubDate>Wed, 21 Apr 2021 13:32:03 +0000</pubDate>
      <guid>https://blog.richardfennell.net/posts/loading-drivers-for-cross-browser-testing-with-selenium/</guid>
      <description>&lt;p&gt;&lt;em&gt;Another post so I don&amp;rsquo;t forget how I fixed a problem&amp;hellip;.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;I have been making sure some Selenium UX tests that were originally written against Chrome also work with other browsers. I have had a few problems, the browser under test failing to load or Selenium not being able to find elements.&lt;/p&gt;
&lt;p&gt;Turns out the solution is to just use the custom driver start-up options, the default constructors don&amp;rsquo;t seem to work for browsers other theran Chrome and Firefox.&lt;/p&gt;</description>
      <content:encoded><![CDATA[<p><em>Another post so I don&rsquo;t forget how I fixed a problem&hellip;.</em></p>
<p>I have been making sure some Selenium UX tests that were originally written against Chrome also work with other browsers. I have had a few problems, the browser under test failing to load or Selenium not being able to find elements.</p>
<p>Turns out the solution is to just use the custom driver start-up options, the default constructors don&rsquo;t seem to work for browsers other theran Chrome and Firefox.</p>
<p>Hence, I not have helper method that creates a driver from me based the a configuration parameter</p>
<pre tabindex="0"><code> internal static IWebDriver GetWebDriver()
    {
        var driverName = GetWebConfigSetting(&#34;webdriver&#34;);
        switch (driverName)
        {
            case &#34;Chrome&#34;:
                return new ChromeDriver();
            case &#34;Firefox&#34;:
                return new FirefoxDriver();
            case &#34;IE&#34;:
                InternetExplorerOptions caps = new InternetExplorerOptions();
                caps.IgnoreZoomLevel = true;
                caps.EnableNativeEvents = false;
                caps.IntroduceInstabilityByIgnoringProtectedModeSettings = true;
                caps.EnablePersistentHover = true;
                return new InternetExplorerDriver(caps);
            case &#34;Edge-Chromium&#34;:
                var service = EdgeDriverService.CreateDefaultService(Directory.GetCurrentDirectory(), &#34;msedgedriver.exe&#34;);
                return new EdgeDriver(service);
            default:
                throw new ConfigurationErrorsException($&#34;{driverName} is not a known Selenium WebDriver&#34;);
        }
    }
</code></pre>]]></content:encoded>
    </item>
    <item>
      <title>Fix for &amp;lsquo;System.BadImageFormatException&amp;rsquo; when running x64 based tests inside a Azure DevOps Release</title>
      <link>https://blog.richardfennell.net/posts/fix-for-system-badimageformatexception-when-running-x64-based-tests-inside-a-azure-devops-release/</link>
      <pubDate>Thu, 23 Apr 2020 10:05:35 +0000</pubDate>
      <guid>https://blog.richardfennell.net/posts/fix-for-system-badimageformatexception-when-running-x64-based-tests-inside-a-azure-devops-release/</guid>
      <description>&lt;p&gt;&lt;em&gt;This is one of those blog posts I write to remind my future self how I fixed a problem.&lt;/em&gt;&lt;/p&gt;
&lt;h3 id=&#34;the-problem&#34;&gt;The Problem&lt;/h3&gt;
&lt;p&gt;I have a release that installs VSTest and runs some integration tests that target .NET 4.6 x64. All these tests worked fine in Visual Studio. However, I got the following errors for all tests when they were run in a release&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;2020-04-23T09:30:38.7544708Z vstest.console.exe &amp;#34;C:agent\_workr1aPaymentServicesdroptestartifactsPaymentService.IntegrationTests.dll&amp;#34;

2020-04-23T09:30:38.7545688Z /Settings:&amp;#34;C:agent\_work\_tempuxykzf03ik2.tmp.runsettings&amp;#34;

2020-04-23T09:30:38.7545808Z /Logger:&amp;#34;trx&amp;#34;

2020-04-23T09:30:38.7545937Z /TestAdapterPath:&amp;#34;C:agent\_workr1aPaymentServicesdroptestartifacts&amp;#34;

2020-04-23T09:30:39.2634578Z Starting test execution, please wait...

2020-04-23T09:30:39.4783658Z A total of 1 test files matched the specified pattern.

2020-04-23T09:30:40.8660112Z   X Can\_Get\_MIDs \[521ms\]

2020-04-23T09:30:40.8684249Z   Error Message:

2020-04-23T09:30:40.8684441Z    Test method PaymentServices.IntegrationTests.ControllerMIDTests.Can\_Get\_MIDs threw exception: 

2020-04-23T09:30:40.8684574Z System.BadImageFormatException: Could not load file or assembly &amp;#39;PaymentServices, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null&amp;#39; or one of its dependencies. An attempt was made to load a program with an incorrect format.

2020-04-23T09:30:40.8684766Z   Stack Trace:

2020-04-23T09:30:40.8684881Z       at PaymentServices.IntegrationTests.ControllerMIDTests.Can\_Get\_MIDs()

…

2020-04-23T09:30:40.9038788Z Results File: C:agent\_work\_tempTestResultssvc-devops\_SVRHQAPP027\_2020-04-23\_10\_30\_40.trx

2020-04-23T09:30:40.9080344Z Total tests: 22

2020-04-23T09:30:40.9082348Z      Failed: 22

2020-04-23T09:30:40.9134858Z ##\[error\]Test Run Failed.
&lt;/code&gt;&lt;/pre&gt;&lt;h3 id=&#34;solution&#34;&gt;Solution&lt;/h3&gt;
&lt;p&gt;I needed to tell &lt;strong&gt;vstest.console.exe&lt;/strong&gt; to run x64 as opposed to it’s default of x32. This can be done with a command line override &lt;strong&gt;–platform:x64&lt;/strong&gt;&lt;/p&gt;</description>
      <content:encoded><![CDATA[<p><em>This is one of those blog posts I write to remind my future self how I fixed a problem.</em></p>
<h3 id="the-problem">The Problem</h3>
<p>I have a release that installs VSTest and runs some integration tests that target .NET 4.6 x64. All these tests worked fine in Visual Studio. However, I got the following errors for all tests when they were run in a release</p>
<pre tabindex="0"><code>2020-04-23T09:30:38.7544708Z vstest.console.exe &#34;C:agent\_workr1aPaymentServicesdroptestartifactsPaymentService.IntegrationTests.dll&#34;

2020-04-23T09:30:38.7545688Z /Settings:&#34;C:agent\_work\_tempuxykzf03ik2.tmp.runsettings&#34;

2020-04-23T09:30:38.7545808Z /Logger:&#34;trx&#34;

2020-04-23T09:30:38.7545937Z /TestAdapterPath:&#34;C:agent\_workr1aPaymentServicesdroptestartifacts&#34;

2020-04-23T09:30:39.2634578Z Starting test execution, please wait...

2020-04-23T09:30:39.4783658Z A total of 1 test files matched the specified pattern.

2020-04-23T09:30:40.8660112Z   X Can\_Get\_MIDs \[521ms\]

2020-04-23T09:30:40.8684249Z   Error Message:

2020-04-23T09:30:40.8684441Z    Test method PaymentServices.IntegrationTests.ControllerMIDTests.Can\_Get\_MIDs threw exception: 

2020-04-23T09:30:40.8684574Z System.BadImageFormatException: Could not load file or assembly &#39;PaymentServices, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null&#39; or one of its dependencies. An attempt was made to load a program with an incorrect format.

2020-04-23T09:30:40.8684766Z   Stack Trace:

2020-04-23T09:30:40.8684881Z       at PaymentServices.IntegrationTests.ControllerMIDTests.Can\_Get\_MIDs()

…

2020-04-23T09:30:40.9038788Z Results File: C:agent\_work\_tempTestResultssvc-devops\_SVRHQAPP027\_2020-04-23\_10\_30\_40.trx

2020-04-23T09:30:40.9080344Z Total tests: 22

2020-04-23T09:30:40.9082348Z      Failed: 22

2020-04-23T09:30:40.9134858Z ##\[error\]Test Run Failed.
</code></pre><h3 id="solution">Solution</h3>
<p>I needed to tell <strong>vstest.console.exe</strong> to run x64 as opposed to it’s default of x32. This can be done with a command line override <strong>–platform:x64</strong></p>
<p><a href="https://blogs.blackmarble.co.uk/wp-content/uploads/sites/2/2020/04/image-1.png"><img alt="image" loading="lazy" src="https://blogs.blackmarble.co.uk/wp-content/uploads/sites/2/2020/04/image_thumb-1.png" title="image"></a></p>
]]></content:encoded>
    </item>
    <item>
      <title>Where do I put my testing effort?</title>
      <link>https://blog.richardfennell.net/posts/where-do-i-put-my-testing-effort/</link>
      <pubDate>Thu, 17 May 2018 20:28:40 +0000</pubDate>
      <guid>https://blog.richardfennell.net/posts/where-do-i-put-my-testing-effort/</guid>
      <description>&lt;p&gt;In the past I have blog on the subject of &lt;a href=&#34;https://blogs.blackmarble.co.uk/rfennell/2013/02/26/for-those-hard-to-mock-moments-microsoft-fakes-or-typemock-isolator/&#34;&gt;using advanced unit test mocking tools to ‘mock the unmockable’&lt;/a&gt;. It is an interesting question to revisit; how important today are units tests where this form of complex mocking is required?&lt;/p&gt;
&lt;p&gt;Of late I have certainly seen a bit of a move towards using more functional style tests; still using unit test frameworks, but relying on APIs as access points with real backend systems such as DBs and WebServices being deployed as test environments.&lt;/p&gt;</description>
      <content:encoded><![CDATA[<p>In the past I have blog on the subject of <a href="https://blogs.blackmarble.co.uk/rfennell/2013/02/26/for-those-hard-to-mock-moments-microsoft-fakes-or-typemock-isolator/">using advanced unit test mocking tools to ‘mock the unmockable’</a>. It is an interesting question to revisit; how important today are units tests where this form of complex mocking is required?</p>
<p>Of late I have certainly seen a bit of a move towards using more functional style tests; still using unit test frameworks, but relying on APIs as access points with real backend systems such as DBs and WebServices being deployed as test environments.</p>
<p>This practice is made far easier than in the past due to cloud services such as <a href="https://azure.microsoft.com/en-gb/">Azure</a> and tools to treat creation of complex environments  as code such as <a href="https://docs.microsoft.com/en-us/azure/azure-resource-manager/resource-group-overview">Azure Resource Manager</a> and <a href="https://azure.microsoft.com/en-gb/services/devtest-lab/">Azure DevTest Labs</a>. Both <a href="https://blogs.blackmarble.co.uk/rfennell/tag/devtest-labs/">myself</a> and my colleague <a href="https://blogs.blackmarble.co.uk/rhepworth/category/lability/">RIk Hepworth</a> have posted widely on  the provisioning of such systems.</p>
<p>However, this type of functional testing is still fairly slow, the environments have to be provisioned from scratch, or spun up from saved images, it all takes time. Hence, there is still the space for fast unit tests, and sometimes, usually due to limitations of legacy codebases that were not designed for testing, there is a need to still ‘mock the un-mockable’.</p>
<p>This is where tools like <a href="https://www.typemock.com/">Typemock Isolator</a> and <a href="https://docs.microsoft.com/en-us/visualstudio/test/isolating-code-under-test-with-microsoft-fakes">Microsoft Fakes</a> are still needed. </p>
<p>It has to be said, both are premium products, you need the top Enterprise SKU of Visual Studio to get Fakes or a Typemock Isolator license for Isolator, but when you have a need them their functionality they are the only option. Whether this be to <a href="https://blogs.blackmarble.co.uk/rfennell/2010/04/22/mocking-sharepoint-for-design-with-typemock-isolator/">mock out a product like SharePoint for faster development cycles</a>, or to provide a great base to write <a href="http://www.everydayunittesting.com/2014/09/from-legacy-code-to-testable-code-introduction.html">unit tests on for a legacy code base prior to refactoring</a>.</p>
<p><a href="https://blogs.blackmarble.co.uk/rfennell/2013/02/26/for-those-hard-to-mock-moments-microsoft-fakes-or-typemock-isolator/">As I have said before</a>, for me Typemock Isolator easily has the edge over Microsoft Fakes, the syntax is so much easier to use. Hence, it is great to see the Typemock Isolator being have further extended with updated versions for <a href="https://www.typemock.com/isolatorpp-product-page/">C++ and now Linux</a>.</p>
<p>So in answer to my own question, testing is a layered process. Where you put your investment is going to be down to your systems needs. It is true, I think we are going to all invest a bit more in functional testing on ‘cheap to build and run’ cloud test labs. But you can’t beat the speed of tools like Typemock for those particularly nasty legacy code bases where it is hard to create a copy of the environment in a modern test lab.</p>
]]></content:encoded>
    </item>
  </channel>
</rss>
