开发者

How to make Test Method using job of another Test Method?

Here is what am I doing :

private String connection = "";

[TestMethod]
public void Connect()
{
    Encrypter encrypter = new Encrypter("64bit");

    String keyword = encrypter.Decrypt("5465465465==");

    // Check if crypter is changed
    Assert.AreEqual(true, encrypter.SetCrypter("AES"));

    this.connection = encrypter.Decrypt
        ("65465465466", keyword);
}

[TestMethod]
public void NhibernateFluentTest()
{
    NHibernate.ISessionFactory session =
        Fluently.Configure().Database(PostgreSQLConfiguratio开发者_如何学JAVAn.Standard.ConnectionString(this.connection)).BuildSessionFactory();

    Assert.IsNotNull(session);
}

"Connect" Test Method is changing connection string which is must be using in "NhibernateFluentTest" Test Method but it's just separate methods and second one can't see first one. How can I solve this trouble ?


To setup a common state that is safe to reuse during your tests, create a Setup method using the appropriate attribute. In MSTest, I believe that is [TestInitialize], but you'll be able to find it. There is a similar method to teardown the state. These methods will then run before and after each test.


Tests should never depend on other tests. If a test fails or succeeds depending on whether another test has been executed, it will be very hard to rely on test results.

I would suggest you refactor your code so that there is a method that prepares the string as needed for both tests, and call that method from them.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜