tdd

How to test 2 methods with common logic?

故事扮演 提交于 2019-12-31 03:14:30
问题 Let's say that I have 2 public methods: func didSelect(data: Data) { // do something self.view.showText(textForData(data)) } func didDismiss(data: Data) { if data.isSomething { self.view.showText(textForData(data)) } ... } private func textForData(data: Data): String { var text: String if data.distance == nil { text = "..." } else if data.distance < 1000 { text = "\(data.distance) m" } else { text = "\(data.distance / 1000) km" } return text } Both of them depend on the formatting logic of

Assert to compare two lists of objects C#

柔情痞子 提交于 2019-12-30 11:22:14
问题 I am currently trying to learn how to use unit testing, and I have created the actual list of 3 animal objects and the expected list of 3 animal objects. The question is how do I Assert to check the lists are equal? I have tried CollectionAssert.AreEqual and Assert.AreEqual but to no avail. Any help would be appreciated. The test method: [TestMethod] public void createAnimalsTest2() { animalHandler animalHandler = new animalHandler(); // arrange List<Animal> expected = new List<Animal>();

Anyone done an Objective-C Xode version of Osherove´s TDD Kata “String Calculator”?

大城市里の小女人 提交于 2019-12-30 10:37:16
问题 Always trying to code better and I am interested in doing TDD for Objective-C and Xcode. Do you know any post that implement something like Roy Osherove´s "String Calculator"-Kata Update: trying to find out how to speed up TDD on iOS 回答1: I did that. You can find the screencast and the Xcode project here in my blog. I’ve written the text around it in german, but you should have no trouble playing the video or finding the download link. 回答2: I'd use NSPredicate like this: NSPredicate * parsed

Java mock database connection [closed]

余生长醉 提交于 2019-12-30 04:00:28
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed last year . I want to test class with make db connection. Class that I want to test accept as param in constructor Connection class. I want to pass mock object to the constructor. Can you tell me good framework with example how to mock db connection? 回答1: You can use MockRunner, which has support for JDBC. General mocking

How can I get my jasmine tests fixtures to load before the javascript considers the document to be “ready”?

我是研究僧i 提交于 2019-12-30 03:55:08
问题 I am fairly certain that the issue is that the jquery bindings set to run on $(document).ready do not have the fixture html available to them. So when my events occur that are intended to make a change to the DOM via a jquery function, nothing happens, and my tests fail. I saw a "solution" to this problem here, but that solution which did work for me, required changing my working jquery function to bind with the .live method instead of the .click method. I have two issue with this. First I do

Cuke4Nuke or SpecFlow?

拥有回忆 提交于 2019-12-29 11:48:11
问题 I am trying to decide if I should use Cuke4Nuke or SpecFlow. What are the pro/cons of each? Opinions on which is better and why. Thanks! 回答1: (I might be biased because I am involved with SpecFlow, but here my thoughts...) Cuke4Nuke is very close to Cucumber. This promises a lot of advantages: Compatibility Getting new features from Cucumber when Cucumber evolves (at least in theory, but language support is an example for this) Being a real part of the Cucumber community and the Cucumber

Can I test method call order with AAA syntax in Rhino-Mocks 3.6?

泄露秘密 提交于 2019-12-29 07:30:32
问题 Is it possible to test for the following example if the Method1 called 1st, then Method2 called after and then Method3 by using the AAA syntax, in Rhino-mocks 3.6 ? // Assert var mock = MockRepository.GenerateMock<ISomeService>(); // Act myObject.Service = mock; // How should I change this part to ensure that Rhino Mocks check the call order as well? mock.AssertWasCalled(m=>m.Method1()); mock.AssertWasCalled(m=>m.Method2()); mock.AssertWasCalled(m=>m.Method3()); 回答1: Here's one way to do it..

How do you unit test regular expressions?

蓝咒 提交于 2019-12-29 02:33:06
问题 I'm new to TDD, and I find RegExp quite a particular case. Is there any special way to unit test them, or may I just treat them as regular functions? 回答1: You should always test your regexen, much like any other chunk of code. They're at the most simple a function that takes a string and returns a bool, or returns an array of values. Here are some suggestions on what to think about when it comes to designing unit tests for regexen. These are not not hard and fast prescriptions for unit test

How do I mock/fake the session object in ASP.Net Web forms?

时间秒杀一切 提交于 2019-12-28 12:32:49
问题 Is there a way to mock/fake the session object in ASP.Net Web forms when creating unit tests? I am currently storing user details in a session variable which is accessed by my business logic. When testing my business logic in isolation, the session is not available. This seems to indicate a bad design (though I'm not sure). Should the business logic layer be accessing session variables in the first place? If so, then how would I go about swapping the user details with a fake object for

NUnit Test Run Order

亡梦爱人 提交于 2019-12-28 08:06:06
问题 By default nunit tests run alphabetically. Does anyone know of any way to set the execution order? Does an attribute exist for this? 回答1: Your unit tests should each be able to run independently and stand alone. If they satisfy this criterion then the order does not matter. There are occasions however where you will want to run certain tests first. A typical example is in a Continuous Integration situation where some tests are longer running than others. We use the category attribute so that