jasmine: Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL

Having an argument in your it function (done in the code below) will cause Jasmine to attempt an async call. //this block signature will trigger async behavior. it(“should work”, function(done){ //… }); //this block signature will run synchronously it(“should work”, function(){ //… }); It doesn’t make a difference what the done argument is named, its … Read more

How can we run a test method with multiple parameters in MSTest?

EDIT 4: Looks like this is completed in MSTest V2 June 17, 2016: https://blogs.msdn.microsoft.com/visualstudioalm/2016/06/17/taking-the-mstest-framework-forward-with-mstest-v2/ Original Answer: As of about a week ago in Visual Studio 2012 Update 1 something similar is now possible: [DataTestMethod] [DataRow(12,3,4)] [DataRow(12,2,6)] [DataRow(12,4,3)] public void DivideTest(int n, int d, int q) { Assert.AreEqual( q, n / d ); } EDIT: It … Read more

How to tell a Mockito mock object to return something different the next time it is called?

You could also Stub Consecutive Calls (#10 in 2.8.9 api). In this case, you would use multiple thenReturn calls or one thenReturn call with multiple parameters (varargs). import static org.junit.Assert.assertEquals; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import org.junit.Before; import org.junit.Test; public class TestClass { private Foo mockFoo; @Before public void setup() { setupFoo(); } @Test … Read more

How to use Mockito with JUnit5

There are different ways to use Mockito – I’ll go through them one by one. Manually Creating mocks manually with Mockito::mock works regardless of the JUnit version (or test framework for that matter). Annotation Based Using the @Mock-annotation and the corresponding call to MockitoAnnotations::initMocks to create mocks works regardless of the JUnit version (or test … Read more

How do you mock out the file system in C# for unit testing?

Edit: Install the NuGet package System.IO.Abstractions. This package did not exist when this answer was originally accepted. The original answer is provided for historical context below: You could do it by creating an interface: interface IFileSystem { bool FileExists(string fileName); DateTime GetCreationDate(string fileName); } and creating a ‘real’ implementation which uses System.IO.File.Exists() etc. You can … Read more

How to set up Google C++ Testing Framework (gtest) with Visual Studio 2005

(These instructions get the testing framework working for the Debug configuration. It should be pretty trivial to apply the same process to the Release configuration.) Get Google C++ Testing Framework Download the latest gtest framework Unzip to C:\gtest Build the Framework Libraries Open C:\gtest\msvc\gtest.sln in Visual Studio Set Configuration to “Debug” Build Solution Create and … Read more

How to properly assert that an exception gets raised in pytest?

pytest.raises(Exception) is what you need. Code import pytest def test_passes(): with pytest.raises(Exception) as e_info: x = 1 / 0 def test_passes_without_info(): with pytest.raises(Exception): x = 1 / 0 def test_fails(): with pytest.raises(Exception) as e_info: x = 1 / 1 def test_fails_without_info(): with pytest.raises(Exception): x = 1 / 1 # Don’t do this. Assertions are caught … Read more

What is unit testing? [closed]

Unit testing is, roughly speaking, testing bits of your code in isolation with test code. The immediate advantages that come to mind are: Running the tests becomes automate-able and repeatable You can test at a much more granular level than point-and-click testing via a GUI Note that if your test code writes to a file, … Read more