1

I have unit tests that require they run specifically as x86 and x64. The problem I'm having is I can't ever run all unit tests because I have to switch the framework from the Test menu. Is there any better way to do this in a more automated fashion? Ideally there would be an Attribute I could use to specify if a test was specifically x86 or x64. Here's an example of my code:

[TestMethod]
public void Testx86_Success()
{
    if (!Environment.Is64BitProcess)
    {
        //Arrange
        ...

        //Act
        ...

        //Assert
        Assert.IsTrue(true);
    }
    else
    {
        Assert.Inconclusive("Can't test x64 while running in x86 process.");
    }
}

[TestMethod]
public void Testx64_Success()
{
    if (Environment.Is64BitProcess)
    {
        //Arrange
        ...

        //Act
        ...

        //Assert
        Assert.IsTrue(true);
    }
    else
    {
        Assert.Inconclusive("Can't test x86 while running in x64 process.");
    }
}
T.S.
  • 18,195
  • 11
  • 58
  • 78
LorneCash
  • 1,446
  • 2
  • 16
  • 30

1 Answers1

0

You can declare conditional compilation variable and use it

#if comp_x64
[TestMethod]
public void Testx64_Success()
{
    if (Environment.Is64BitProcess)
    {
        //Arrange
        ...

        //Act
        ...

        //Assert
        Assert.IsTrue(true);
    }
    else
    {
        Assert.Inconclusive("Can't test x86 while running in x64 process.");
    }
}
#else
   . . . . your x86 test 
#endif
T.S.
  • 18,195
  • 11
  • 58
  • 78
  • I didn't try that but I'm assuming that would remove them from the list to be tested. I wouldn't want to forget about them. Thank you for providing this option but I think I like my current solution better. – LorneCash Apr 29 '18 at 08:01