tdd

What are the primary differences between TDD and BDD?

那年仲夏 提交于 2019-11-26 18:44:35
问题 Test Driven Development has been the rage in the .NET community for the last few years. Recently, I have heard grumblings in the ALT.NET community about BDD. What is it? What makes it different from TDD? 回答1: I understand BDD to be more about specification than testing . It is linked to Domain Driven Design (don't you love these *DD acronyms?). It is linked with a certain way to write user stories, including high-level tests. An example by Tom ten Thij: Story: User logging in As a user I want

C# - Asserting two objects are equal in unit tests

余生颓废 提交于 2019-11-26 18:31:01
问题 Either using Nunit or Microsoft.VisualStudio.TestTools.UnitTesting. Right now my assertion fails. [TestMethod] public void GivenEmptyBoardExpectEmptyBoard() { var test = new Board(); var input = new Board() { Rows = new List<Row>() { new Row(){Cells = new List<int>(){0,0,0,0}}, new Row(){Cells = new List<int>(){0,0,0,0}}, new Row(){Cells = new List<int>(){0,0,0,0}}, new Row(){Cells = new List<int>(){0,0,0,0}}, } }; var expected = new Board() { Rows = new List<Row>() { new Row(){Cells = new

How do I mock a class without an interface?

◇◆丶佛笑我妖孽 提交于 2019-11-26 18:04:07
问题 I am working on .NET 4.0 using C# in Windows 7. I want to test the communication between some methods using mock. The only problem is that I want to do it without implementing an interface. Is that possible? I just read a lot of topics and some tutorials about mock objects, but all of them used to mock interfaces, and not the classes. I tried to use Rhino and Moq frameworks. 回答1: Simply mark any method you need to fake as virtual (and not private). Then you will be able to create a fake that

Static class/method/property in unit test, stop it or not

天涯浪子 提交于 2019-11-26 16:41:34
问题 Update should a static class/method/property be used in a unit test development environment, given that it is no way to test it without introducing a wrapper that is again not testable? Another scenario is that when the static members are used within the unit tested target, the static memeber cannot be mocked. Thus, you have to test the static meembers when the unit tested target is tested. You want to isolate it when the static member performs calculation. 回答1: Testing static method is no

“Web interface” to PHPUnit tests?

主宰稳场 提交于 2019-11-26 15:44:51
问题 Is there a simple "Web interface" to running PHPUnit test suites? i.e. a PHP script that runs the test on the command line, and outputs a nicely formatted HTML result. I develop web applications, and the day-to-day workflow usually switches between the IDE and the browser. I would like to have the unit testing in the same environment. I'm looking for something really simple and PHP based - I am planning to get into phpUnderControl (which has the functionality I'm looking for) but not yet. 回答1

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

妖精的绣舞 提交于 2019-11-26 15:25:05
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? Gishu My approach towards this is heavily biased on the Growing Object-Oriented Software Guided by Tests (GOOS) book that I just read, but it's the best

Do polymorphism or conditionals promote better design?

久未见 提交于 2019-11-26 15:13:46
问题 I recently stumbled across this entry in the google testing blog about guidelines for writing more testable code. I was in agreement with the author until this point: Favor polymorphism over conditionals: If you see a switch statement you should think polymorphisms. If you see the same if condition repeated in many places in your class you should again think polymorphism. Polymorphism will break your complex class into several smaller simpler classes which clearly define which pieces of the

Mocking vs. Spying in mocking frameworks

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-26 15:11:44
问题 In mocking frameworks, you can mock an object or spy on it. What's the difference between the two and when would/should I use one over the other? Looking at mockito, for example, I see similar things being done using spies and mocks, but I am unsure as to the distinction between the two. 回答1: Mock object replace mocked class entirely, returning recorded or default values. You can create mock out of "thin air". This is what is mostly used during unit testing. When spying, you take an existing

F# development and unit testing?

孤街醉人 提交于 2019-11-26 15:08:21
问题 I just got started with F#, which is my first functional language. I have been working quasi-exclusively with C#, and enjoy a lot how F# leads me to re-think how I write code. One aspect I find a bit disorienting is the change in the process of writing code. I have been using TDD for years in C# now, and really appreciate to have unit tests to know where I am at. So far, my process with F# has been to write some functions, play with them with the interactive console until I am "reasonably"

How to get started on TDD with Ruby on Rails? [closed]

我的梦境 提交于 2019-11-26 14:57:53
问题 I am familiar with the concepts (took testing classes in college), but I am not sure how to really use them yet since I never worked on a "real" TDD project. I am about to start the development of a project using Ruby on Rails (most likely using 2.3). This application will be used to manage data, users and some files. It won't be too complicated at first but might scale a lot in the next 6 months so I feel this is the right time to get more into TDD. I've got a basic idea on how to do it, but