Setting HttpContext.Current.Session in a unit test

I have a web service I am trying to unit test. In the service it pulls several values from the HttpContext like so: m_password = (string)HttpContext.Current.Session[“CustomerId”]; m_userID = (string)HttpContext.Current.Session[“CustomerUrl”]; in the unit test I am creating the context using a simple worker request, like so: SimpleWorkerRequest request = new SimpleWorkerRequest(“”, “”, “”, null, new StringWriter()); … Read more

Unit testing Anti-patterns catalogue

Locked. This question and its answers are locked because the question is off-topic but has historical significance. It is not currently accepting new answers or interactions. anti-pattern : there must be at least two key elements present to formally distinguish an actual anti-pattern from a simple bad habit, bad practice, or bad idea: Some repeated … Read more

How can I call a custom Django manage.py command directly from a test driver?

I want to write a unit test for a Django manage.py command that does a backend operation on a database table. How would I invoke the management command directly from code? I don’t want to execute the command on the Operating System’s shell from tests.py because I can’t use the test environment set up using … Read more

What are some popular naming conventions for Unit Tests? [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for … Read more

How to compare Lists in Unit Testing

How can this test fail? [TestMethod] public void Get_Code() { var expected = new List<int>(); expected.AddRange(new [] { 100, 400, 200, 900, 2300, 1900 }); var actual = new List<int>(); actual.AddRange(new [] { 100, 400, 200, 900, 2300, 1900 }); Assert.AreEqual(expected, actual); // Assert.AreSame(expected, actual) fails // Assert.IsTrue(expected.Equals(actual)) fails } 7 Answers 7

How to assert two list contain the same elements in Python? [duplicate]

This question already has answers here: How to efficiently compare two unordered lists (not sets) in Python? (10 answers) Closed 5 years ago. When writing test cases, I often need to assert that two list contain the same elements without regard to their order. I have been doing this by converting the lists to sets. … Read more