tdd

How do I unit-test saving file to the disk?

好久不见. 提交于 2019-12-17 03:09:35
问题 I know that it's strongly recommended to run unit-tests in separation from file system , because if you do touch file system in your test, you also test file system itself. OK, that's reasonable. My question is, if I want to test file saving to the disk, what do I do? As with database, I separate an interface that is responsible for database access, and then create another implementation of this for my tests? Or may be there's some other way? 回答1: My approach towards this is heavily biased on

JavaScript unit test tools for TDD

蓝咒 提交于 2019-12-16 19:57:17
问题 This post is a Community Wiki . Edit existing answers to improve this post. It is not currently accepting new answers. I've looked into and considered many JavaScript unit tests and testing tools, but have been unable to find a suitable option to remain fully TDD compliant. So, is there a JavaScript unit test tool that is fully TDD compliant? 回答1: Karma or Protractor Karma is a JavaScript test-runner built with Node.js and meant for unit testing. The Protractor is for end-to-end testing and

JavaScript unit test tools for TDD

久未见 提交于 2019-12-16 19:57:15
问题 This post is a Community Wiki . Edit existing answers to improve this post. It is not currently accepting new answers. I've looked into and considered many JavaScript unit tests and testing tools, but have been unable to find a suitable option to remain fully TDD compliant. So, is there a JavaScript unit test tool that is fully TDD compliant? 回答1: Karma or Protractor Karma is a JavaScript test-runner built with Node.js and meant for unit testing. The Protractor is for end-to-end testing and

TDD-friendly Singleton-like class

若如初见. 提交于 2019-12-14 04:25:37
问题 I have repository class that is used by at least 2 other classes. This repository class needs to be initialized - which is high in cost (querying database). Now, I create separate instances of repository wherever I need it. The thing is, that everytime I create repository it has to be initialized. How to design such repository to be TDD-friendly? The first thing in my mind was Singleton but it's not the solution. 回答1: Do you use any type of IOC container? Unity is my container of choice, and

How can I deal with too Many Mock Expectations in unit tests?

南笙酒味 提交于 2019-12-14 03:59:11
问题 I am writing unit tests for my presentation class in MVP pattern.But I am having trouble to write mock setup code. I have a presenter and when presenter's Load method called I want to test view should load class properties, table fields, data types,set presenter.... So When I have a different thing to do when presenter load always I have to add new expectation to test. And test is getting bigger every time. [Test] public void When_Presenter_Loads_View_Should_Display_Selected_Class_Properties(

Developing to an interface with TDD

依然范特西╮ 提交于 2019-12-14 03:46:25
问题 I'm a big fan of TDD and use it for the vast majority of my development these days. One situation I run into somewhat frequently, though, and have never found what I thought was a "good" answer for, is something like the following (contrived) example. Suppose I have an interface, like this (writing in Java, but really, this applies to any OO language): public interface PathFinder { GraphNode[] getShortestPath(GraphNode start, GraphNode goal); int getShortestPathLength(GraphNode start,

QUnit stubbing out methods on a dependency breaks tests against that dependency

为君一笑 提交于 2019-12-14 01:34:23
问题 In Google Apps Script, I'm unit-testing an app that I'm working on, using QUnit, using test-driven-development. The code under test I am, right now, working on fully testing, and then developing, the following function: /** * * Creates a Sheet from a long string of data * @param { string } data : the long string of data * @returns { Sheet } the newly-created Sheet **/ function createSheetFrom(data) { // if data is not in the form of a string, we've got a problem if (data !== data.toString())

newbie can't define a method in ruby for cucumber test pass

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-13 22:15:31
问题 I am trying to learn cucumber, here's an example code from a book: class Output def messages @messages ||= [] end def puts(message) messages << message end end def output @output ||= Output.new end Given /^I am not yet playing$/ do end When /^I start a new game$/ do game = Codebreaker::Game.new(output) game.start end Then /^I should see "([^"]*)"$/ do |message| output.messages.should include(message) end When I run this spec, I get this error: Scenario: start game # features/codebreaker

How to mock JQuery with Jasmine?

拟墨画扇 提交于 2019-12-13 12:27:42
问题 How can I test that a certain JQuery selector has been executed with Jasmine? I'm trying to do the following: spyOn($.fn, 'init').andCallThrough(); // my code expect($.init).toHaveBeenCalled(); But after this call, $('div') returns Object { selector="div", context=document, NaN=div.spec, more...} , though it has to return (and $.fn.init('div') does return it): [div.jasmine_reporter, div.banner, div.logo, 4 more...] . This stuff naturally breaks the code since the JQuery object is no longer

MSTest: how to increase test time

心已入冬 提交于 2019-12-13 12:24:12
问题 I have one test that needs to work more then 1 minute (VS2008, MSTest, tests are launched from the VisualStudio): const int TestTimeout = 1; [TestMethod] [Timeout(10*60*1000)] // 10 minutes public void Login_ExpirationFail_Test() { IAuthenticationParameters parameters = new AuthenticationParameters(...); LdapAuthentication auth1 = new LdapAuthentication(); IAuthenticationLoginResult res = auth1.Login(parameters); Assert.IsNotNull(res); Assert.IsFalse(string.IsNullOrEmpty(res.SessionId));