Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6704965
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:20:57+00:00 2026-05-26T07:20:57+00:00

I always try to stick to one assertion per test but sometimes I’m having

  • 0

I always try to stick to one assertion per test but sometimes I’m having troubles in doing so.

For example.

Say I’ve written a cryptographic class that encrypt and decrypts strings.

public class CryptoDummy
{
    public string Decrypt(string value)
    {
    }

    public string Encrypt(string value)
    {
    }
}

How would I create my unit test if the decryption is depended upon the output of the encryption ?

Most of my tests if not all up until now are composed of one method call per test and one assertion per test.

So to the point, is it fine to have multiple calls per test and assert the final results made by the method I called last ?

public class CryptoDummyTest
{
    private static CryptoDummy _cryptoDummy;

    // Use ClassInitialize to run code before running the first test in the class
    [ClassInitialize]
    public static void MyClassInitialize(TestContext testContext)
    {
        _cryptoDummy = new CryptoDummy();
    }

    [TestMethod]
    public void Encrypt_should_return_ciphered_64string_when_passing_a_plaintext_value()
    {
        const string PLAINTEXT_VALUE = "anonymous@provider.com";

        string cipheredString = _cryptoDummy.Encrypt(PLAINTEXT_VALUE);

        Assert.IsTrue(cipheredString != PLAINTEXT_VALUE);
    }

    [TestMethod]
    public void Decrypt_should_return_plaintext_when_passing_a_ciphered_value()
    {
        const string PLAINTEXT_VALUE = "anonymous@provider.com";

        string cipheredString = _cryptoDummy.Encrypt(PLAINTEXT_VALUE);

        string plaintextString = _cryptoDummy.Decrypt(cipheredString);

        Assert.IsTrue(plaintextString == PLAINTEXT_VALUE);
    }
}

Thank you in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T07:20:58+00:00Added an answer on May 26, 2026 at 7:20 am

    You shouldnt have one test depending upon another. The best way to do this would be to output the encrypted text somewhere and save it. Then on the decrypt text test you could start with an encrypted text and test you decrypt it correctly. If you use the same encryption key (which is fine for testing) the encrypted string will always be the same. So change your second unit test to something like this:

    [TestMethod]
    public void Decrypt_should_return_plaintext_when_passing_a_ciphered_value()
    {
    
        const string PLAINTEXT_VALUE = "anonymous@provider.com";
    
        string cipheredString = "sjkalsdfjasdljs"; // ciphered value captured
    
        string plaintextString = _cryptoDummy.Decrypt(cipheredString);
    
        Assert.IsTrue(plaintextString == PLAINTEXT_VALUE);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This does not always happen, but sometimes when I try to build a (large)
I try to use this dll: http://www.eggheadcafe.com/articles/20050129.asp but not working. i always get timeout
I always try to avoid to return string literals, because I fear they aren't
I always try to do the following: <label><input type=checkbox /> Some text</label> or <label
Background: I always try to ensure the following tenet in my projects: After a
Whenever I use WCF, I always try to make immutable classes that end up
I always hear that programmers try to pick the right tool for the job.
Should I always wrap external resource calls in a try-catch? (ie. calls to a
When I try to bind port 80 to a socket in c, i always
Do you always use a second-level cache in Hibernate or do you first try

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.