如何从[TestMethod]中获取“A”的值以在[TestClass]中执行查找?我尝试将它移到它自己的类中,并且完全脱离了TestMethod,但是我的应用程序最终抓取了生成的下一个数字,而不是测试方法中使用的那个。如何从testmethod获取c#中字符串的值在C#中
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace Classic
{
[TestMethod]
public void MyFirstTest()
{
string A = "L" + (String.Format("{0:MMddyyyy}", SafeRandom.GetRandomNext(10).ToString());
//some test steps go here
}
}
[TestClass()]
public class TestScenario
{
public void RunLookupMyString()
{
//Use string above to perform a lookup
}
}
public class SafeRandom
{
private static readonly Object RandLock = new object();
private static readonly Random Random = new Random();
public static int GetRandomNext(int maxValue)
{
lock (RandLock)
{
return Random.Next(maxValue);
}
}
public static int GetRandomNext(int minValue, int maxValue)
{
lock (RandLock)
{
return Random.Next(minValue, maxValue);
}
}
}
这段代码甚至不会编译。你期待它做什么? – RJM
@RJM我只是想从Testmethod中获得值,所以我可以在另一种方法中使用它。 – Tester
编辑您的代码示例,以便它有道理。事实上,你的代码使你的问题很不明确。 – hatchet