How to properly use unit-testing’s assertRaises() with NoneType objects? [duplicate]

This question already has answers here: How do you test that a Python function throws an exception? (18 answers) Closed 4 years ago. I did a simple test case: def setUp(self): self.testListNone = None def testListSlicing(self): self.assertRaises(TypeError, self.testListNone[:1]) and I am expecting test to pass, but I am getting exception: Traceback (most recent call last): … Read more

Test method is inconclusive: Test wasn’t run. Error?

I have a test class and below I have posted a sample test from the test class namespace AdminPortal.Tests.Controller_Test.Customer { [TestClass] public class BusinessUnitControllerTests { private IBusinessUnitRepository _mockBusinessUnitRepository; private BusinessUnitController _controller; [TestInitialize] public void TestInitialize() { _mockBusinessUnitRepository = MockRepository.GenerateMock<IBusinessUnitRepository>(); _controller = new BusinessUnitController(_mockBusinessUnitRepository); } [TestCleanup] public void TestCleanup() { _mockBusinessUnitRepository = null; _controller.Dispose(); _controller = … Read more

How to test code dependent on environment variables using JUnit?

I have a piece of Java code which uses an environment variable and the behaviour of the code depends on the value of this variable. I would like to test this code with different values of the environment variable. How can I do this in JUnit? I’ve seen some ways to set environment variables in … Read more

Why am I getting an Exception with the message “Invalid setup on a non-virtual (overridable in VB) member…”?

I have a unit test where I have to mock a non-virtual method that returns a bool type public class XmlCupboardAccess { public bool IsDataEntityInXmlCupboard(string dataId, out string nameInCupboard, out string refTypeInCupboard, string nameTemplate = null) { return IsDataEntityInXmlCupboard(_theDb, dataId, out nameInCupboard, out refTypeInCupboard, nameTemplate); } } So I have a mock object of XmlCupboardAccess … Read more

Assert equals between 2 Lists in Junit

How can I make an equality assertion between lists in a JUnit test case? Equality should be between the content of the list. For example: List<String> numbers = Arrays.asList(“one”, “two”, “three”); List<String> numbers2 = Arrays.asList(“one”, “two”, “three”); List<String> numbers3 = Arrays.asList(“one”, “two”, “four”); // numbers should be equal to numbers2 //numbers should not be equal … Read more

How to output in CLI during execution of PHP Unit tests?

When running a PHPUnit test, I would like to be able to dump output so I can debug one or two things. I have tried the following (similar to the PHPUnit Manual example); class theTest extends PHPUnit_Framework_TestCase { /** * @outputBuffering disabled */ public function testOutput() { print_r(“Hello World”); print “Ping”; echo “Pong”; $out = … Read more