tdd

How to mock specific function in object using Jest?

余生长醉 提交于 2019-12-04 05:35:48
I'm testing a React/Reflux application using Jest. I have the following function in a store: onLoad: function() { console.log("ORIGINAL LOAD"); // http request here } I'm trying to mock it out so that it just does what it needs to do without doing the actual network stuff: beforeEach(function() { // mock out onLoad so instead of making API call the store gets test data PostStore.onLoad = jest.genMockFunction().mockImplementation(function () { var p1 = new Post( "54da7df5119025513400000a", // id "Test Post", // title "Kji6ftLjUqhElgnqOBqMUKxYONpU7nK/cu6jTA==\n", // owner anonId "Test Course 1",

How do you Unit Test an .EXE with 3rd party dll?

血红的双手。 提交于 2019-12-04 05:17:54
I'm still learning the dark arts of TDD and recently I've been trying to learn how to do TDD in VB6 and what I basically narrow down the list to was the free simplyvbunit and the most costly vbunit3. My application is an richtext editor with plenty of 3rd party dll and I was scouring high and low in Google to find how to do unit test this exe file. So my question is how do you unit test an exe file? Especially in the context for VB6 and if you have any good example with vbunit3 or simplyvbunit, you're simply a lifesaver as I'm drowing in the material right now and I still can't write one unit

Benefits of TDD in machine learning

爷,独闯天下 提交于 2019-12-04 05:05:36
As far as I know typical workflow of TDD is based on black box testing. First we define interface then write one or set of test and then we implement code that pass all tests. So look at the example below: from abc import ABCMeta class InterfaceCalculator: __metaclass__ = ABCMeta @abstractmethod def calculate_mean(self): pass Exemplary test case from unittest import TestCase class TestInterfaceCalculator(TestCase): def test_should_correctly_calcluate_mean(self): X=[1,1] expected_mean = 1 calcluator =Calculator() self.assertAlmostEqual(calculator.calculate_mean(X), expected_mean) I skip

How to assert that an action was called

冷暖自知 提交于 2019-12-04 04:38:25
问题 I need to asset an action called by a mock component. public interface IDispatcher { void Invoke(Action action); } public interface IDialogService { void Prompt(string message); } public class MyClass { private readonly IDispatcher dispatcher; private readonly IDialogservice dialogService; public MyClass(IDispatcher dispatcher, IDialogService dialogService) { this.dispatcher = dispatcher; this.dialogService = dialogService; } public void PromptOnUiThread(string message) { dispatcher.Invoke(()

Rhino Mocks Partial Mock

主宰稳场 提交于 2019-12-04 04:23:42
I am trying to test the logic from some existing classes. It is not possible to re-factor the classes at present as they are very complex and in production. What I want to do is create a mock object and test a method that internally calls another method that is very hard to mock. So I want to just set a behaviour for the secondary method call. But when I setup the behaviour for the method, the code of the method is invoked and fails. Am I missing something or is this just not possible to test without re-factoring the class? I have tried all the different mock types (Strick,Stub,Dynamic,Partial

What is your favorite/recommended project structure and file structure for Unit Testing using Boost?

爷,独闯天下 提交于 2019-12-04 04:20:22
I have not used Unit Testing so far, and I intend to adopt this procedure. I was impressed by TDD and certainly want to give it a try - I'm almost sure it's the way to go. Boost looks like a good choice, mainly because it's being maintained. With that said, how should I go about implementing a working and elegant file-structure and project-structure ? I am using VS 2005 in Win XP. I have been googling about this and was more confused than enlightened. Our Boost based Testing structure looks like this: ProjectRoot/ Library1/ lib1.vcproj lib1.cpp classX.cpp ... Library2/ lib2.vcproj lib2.cpp

Using TDD to develop file traversing code in Java

随声附和 提交于 2019-12-04 04:00:51
问题 I had to implement some code to traverse a directory structure and return a list of files found. The requirements were pretty simple: Given a base directory, find all files (which are not directories themselves) within. If a directory is found, repeat step 1 for it. I wanted to develop the code using TDD. As I started writing the tests, I realized that I was mocking class File , so I could intercept calls to File.isDirectory() and so on. In this way, I was forcing myself to use a solution

How do I do TDD efficiently with NHibernate?

女生的网名这么多〃 提交于 2019-12-04 03:47:10
It seems to me that most people write their tests against in-memory, in-process databases like SQLite when working with NHibernate. I have this up and running but my first test (that uses NHibernate) always takes between 3-4 seconds to execute. The next test runs much faster. I am using FluentNhibernate to do the mapping but get roughly the same timings with XML mapping files. For me the 3-4 second delay seriously disrupts my flow. What is the recomended way of working with TDD and NHibernate? Is it possible to mock ISession to unit test the actual queries or can this only be done with in

Cucumber: Automatic step file creation?

左心房为你撑大大i 提交于 2019-12-04 03:42:01
问题 When i run cucumber it displays the possible steps that i should define, an example from the RSpec book: 1 scenario (1 undefined) 4 steps (4 undefined) 0m0.001s You can implement step definitions for undefined steps with these snippets: Given /^I am not yet playing$/ do pending end When /^I start a new game$/ do pending end Then /^the game should say “Welcome to CodeBreaker”$/ do pending end Then /^the game should say “Enter guess:”$/ do pending end Is there a way that it will automaticly

How to fix err Jest has detected the following 3 open handles potentially keeping Jest from exiting

依然范特西╮ 提交于 2019-12-04 03:31:42
问题 Just starting to work on some node app using jest for testing. express-generator used for scaffolding. On first test I get following error: Jest has detected the following 3 open handles potentially keeping Jest from exiting Steps to reproduce: git clone git@github.com:gandra/node-jest-err-demo.git cd node-jest-err-demo npm install cp .env.example .env npm run test npx envinfo --preset jest output: npx: installed 1 in 1.896s System: OS: macOS High Sierra 10.13.4 CPU: x64 Intel(R) Core(TM) i7