简体   繁体   中英

MSTest V2 with x86 and x64

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.");
    }
}

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM