tdd

Checking the results of a Factory in a unit test

两盒软妹~` 提交于 2019-11-29 06:20:56
问题 I have developed some classes with similar behavior, they all implement the same interface. I implemented a factory that creates the appropriate object and returns the interface. I am writing a unit test for the factory. All you get back is an interface to the object. What is the best way to test that the factory has worked correctly? I would like to know the answer in Java, but if there is a solution that crosses languages I would like to know it. Number 2. in the answer, would be done like

How to unit test private methods in BDD / TDD?

不打扰是莪最后的温柔 提交于 2019-11-29 06:01:06
I am trying to program according to Behavior Driven Development, which states that no line of code should be written without writing failing unit test first. My question is, how to use BDD with private methods? How can I unit test private methods? Is there better solution than: - making private methods public first and then making them private when I write public method that uses those private methods; or - in C# making all private methods internal and using InternalsVisibleTo attribute. When you write code test-first, you write against the public interface. There are no private methods at

TDD FIRST principle

微笑、不失礼 提交于 2019-11-29 05:33:57
问题 I am not understanding how the TDD FIRST principle isn't being adhered to in the following code. These are my notes about the FIRST principle: Fast : run (subset of) tests quickly (since you'll be running them all the time) Independent : no tests depend on others, so can run any subset in any order Repeatable : run N times, get same result (to help isolate bugs and enable automation) Self-checking : test can automatically detect if passed (no human checking of output) Timely : written about

Moq - mock.Raise should raise event in tested unit without having a Setup

寵の児 提交于 2019-11-29 04:49:42
问题 I have a presenter class, that attaches an event of the injected view. Now I would like to test the presenter reacting on correctly on the event. This is the view interface IView: public interface IView { event EventHandler MyEvent; void UpdateView(string test); } This ist the view implementing IView public partial class MyView : IView { public event EventHandler MyEvent; public MyView() { this.combo.SelectedIndexChanged += this.OnSelectedIndexChanged; } public void UpdateView(string test) {

The Purpose of Mocking

喜你入骨 提交于 2019-11-29 03:50:07
问题 What is the purpose of mocking? I have been following some ASP.NET MVC tutorials that use NUnit for testing and Moq for mocking. I am a little unclear about the mocking part of it though. 回答1: The purpose of mocking is to isolate the class being tested from other classes. This is helpful when a class : connects to an external resource (FileSystem, DB, network ... ) is expensive to setup, or not yet available (hardware being developed) slows down the execution of the unit tests has a non

Best way to do TDD in express versions of visual studio(eg VB Express)

▼魔方 西西 提交于 2019-11-29 03:48:09
I have been looking in to doing some test driven development for one of the applications that I'm currently writing(OLE wrapper for an OLE object). The only problem is that I am using the express versions of Visual Studio(for now), at the moment I am using VB express but sometimes I use C# express. Is it possible to do TDD in the express versions? If so what are the bast was to go about it? Cheers. EDIT. By the looks of things I will have to buy the full visual studio so that I can do integrated TDD, hopefully there is money in the budget to buy a copy :). For now I think I will use Nunit like

Multiple or Single Repositories with LINQ

爱⌒轻易说出口 提交于 2019-11-29 03:13:35
问题 I've been reading Chapter 11 (Testable Design Patterns) in the Professional ASP.NET MVC 1.0 book. In the examples in this chapter, data access is split into a number of repositories: IOrderRepository, IProductRepository, etc. That all makes sense: a single repository for a single class of data. However, this breaks down somewhat for me when you consider the links between the tables: an Order contains a number of Products. When the Order class is created by LINQ-to-SQL, the order class will

What's the best way to organize feature files?

耗尽温柔 提交于 2019-11-29 03:05:00
问题 I'm a huge fan of Specflow and BDD. It worked out great for me on a variety of projects. One challenge I haven't solved yet is organizing my feature files and scenarios in a way, which makes it easy to navigate and explore. Imagine one year later someone else wants to come along and learn about the system. Where to start? What's most important, what's less important? Any relations between features? Does the system handle a particular scenario? Has the author thought about this problem? Can

What best practices do you use for testing database queries?

大兔子大兔子 提交于 2019-11-29 03:01:14
问题 I'm currently in the process of testing our solution that has the whole "gamut" of layers: UI, Middle, and the omnipresent Database. Before my arrival on my current team, query testing was done by the testers manually crafting queries that would theoretically return a result set that the stored procedure should return based on various relevancy rules, sorting, what have you. This had the side effect of bugs being filed against the tester's query more often than against the actual query in

Rails fixtures — how do you set foreign keys?

為{幸葍}努か 提交于 2019-11-29 02:54:10
I'm reading about Rails fixtures in this guide (thanks, trevorturk). It appears you define classes in a Yaml file and they're automatically loaded into the test DB -- cool. But if you want to specify that this recipe belongs to that cookbook (or whatever) how do you do that? Are you supposed to specify the values for cookbook.id and recipe.cookbook_id by hand in the Yaml code? (Just a guess -- the guide doesn't show anything like that.) Or is there a more suitable way? You should use named fixtures, which automatically generate an id number for you where you don't provide one. These id numbers