how to handle exceptions in junit

An unexpected exception is a test failure, so you neither need nor want to catch one. @Test public void canConvertStringsToDecimals() { String str = “1.234”; Assert.assertEquals(1.234, service.convert(str), 1.0e-4); } Until service does not throw an IllegalArgumentException because str has a decimal point in it, that will be a simple test failure. An expected exception should … Read more

Mocking using Moq in c#

Classic example which demonstrates that if you cannot unit test a particular component, REFACTOR it! This is why I love what any mocking framework enforces you to do – write decoupled code. In your example, the ProductBusiness class is tightly coupled with the ProductDataAccess class. You could decouple it using (like most of the answers … Read more

Django TestCase testing order

A tenet of unit-testing is that each test should be independent of all others. If in your case the code in testTestA must come before testTestB, then you could combine both into one test: def testTestA_and_TestB(self): # test code from testTestA … # test code from testTestB or, perhaps better would be def TestA(self): # … Read more

How to get PyTest working in Visual Studio

Support for Pytest in Visual Studio has been added on Visual Studio 2019 (16.3 Preview 2) You have to change your project’s test framework by right-clicking it and going to Properties -> Test You can add a pytest.ini to your project to configure pytest further. More info from MS themselves: https://devblogs.microsoft.com/python/whats-new-for-python-in-visual-studio-16-3-preview-2/