tdd

How can this SwingWorker code be made testable

夙愿已清 提交于 2019-12-04 16:24:29
问题 Consider this code: public void actionPerformed(ActionEvent e) { setEnabled(false); new SwingWorker<File, Void>() { private String location = url.getText(); @Override protected File doInBackground() throws Exception { File file = new File("out.txt"); Writer writer = null; try { writer = new FileWriter(file); creator.write(location, writer); } finally { if (writer != null) { writer.close(); } } return file; } @Override protected void done() { setEnabled(true); try { File file = get();

TDD: Which methods do you expose for unit testing?

时间秒杀一切 提交于 2019-12-04 16:18:38
问题 There is one aspect of TDD which I never fully understood. Suppose somebody asked you to implement a simple Stack object. If you've done your design properly, you will come to a very minimal and clean API. Suppose: push() , pop() and isEmpty() . Anything more than that is over-killing the demand, and allowing the user too much room to mess with your code. So now let's suppose you want to unit test your code. How do you go about doing this if all your public methods are just the three shown

Breaking a local dependency to unit test a void method

梦想的初衷 提交于 2019-12-04 15:43:14
I am practicing with mockito, but I am a bit stuck on how to test a method that depends on a call to method in a local object. See the following example: public class Worker { public void work() { Vodka vodka = new Vodka(); vodka.drink(); } } This worker, instead of doing his job, he likes drinking. But I want to add a test to prove that he drinks while he works. But there is no way of doing so, because I must verify that the method drink() is called when the method work is called. I think you agree with me, that this is impossible to test, so I need to break the dependency before starting to

Convert C# unit test names to English (testdox style)

橙三吉。 提交于 2019-12-04 15:42:22
I have a whole bunch of unit tests written in MbUnit and I would like to generate plain English sentences from test names. The concept is introduced here: http://dannorth.net/introducing-bdd This is from the article: public class CustomerLookupTest extends TestCase { testFindsCustomerById() { ... } testFailsForDuplicateCustomers() { ... } ... } renders something like this: CustomerLookup - finds customer by id - fails for duplicate customers - ... Unfortunately the tool quoted in the above article (testdox) is Java based. Is there one for .NET? Sounds like this would be something pretty simple

How TDD works when there can be millions of test cases for a production functionality?

核能气质少年 提交于 2019-12-04 15:19:26
问题 In TDD, you pick a test case and implement that test case then you write enough production code so that the test passes, refactor the codes and again you pick a new test case and the cycle continues. The problem I have with this process is that TDD says that you write enough code only to pass the test you just wrote. What I refer to exactly is that if a method can have e.g. 1 million test cases, what can you do?! Obviously not writing 1 million test cases?! Let me explain what I mean more

Mocha and Chai test fails when testing function with setInterval

主宰稳场 提交于 2019-12-04 14:35:06
I'm new to TDD and working with Mocha and Chai. I have created a test that passes when a value is increased, but when that increase is put within a setInterval, it fails. The objective of this code is to have something move across the screen. function startMovingThing(){ var position = setInterval(function() { moveThing(10); }, 100); } function moveThing(number){ thing.position += number; thingOnScreen.style.left = thing.position + 'px'; } test: describe('Thing', function() { it('should increase position', function(){ assert.increases(startMovingThing, thing, 'position'); }); }); How can I get

How far can you go with JavaScript testing?

旧城冷巷雨未停 提交于 2019-12-04 12:59:35
I'm somewhat informed with TDD and BDD with Ruby/Rails, but I will eventually need to use some form of testing with my JavaScript code. I use MooTools as a JS framework and I absolutely love how well I can organize and modularize my code with its codebase. But, sometimes, when I add new features to my application, I find that the functionality can easily break from how it worked before. When it comes to testing JavaScrtpt code, does the testing itself fall short of user interaction? Is it really only to test the ins and outs of method and (emulated) classes in JavaScript? Or is there a UX

How to debug in Visual Studio with NSpec

◇◆丶佛笑我妖孽 提交于 2019-12-04 12:55:53
how do I debug in visual studio with NSpec? I've resharper installed I need to step into my test code. At least in Visual Studio 2013, the NSpec Test Adapter (by {o} Software) seems to do the trick. Find it in the Extensions gallery. Then just right-click on the test in the Test Explorer and hit Debug. Another good option is to just type System.Diagnostics.Debugger.Launch() in the test you want to debug. You'll get a Visual Studio prompt to debug the test. I would also recommend taking a look at specwatchr . I use a simple trick that let's me debug NSpec with resharper out of the box. The idea

Unit Testing Methods With File IO

别来无恙 提交于 2019-12-04 11:17:38
问题 I'm trying to get into the habit of writing unit tests, I've written a few before but they've usually been quite basic...I'd like to start making a move to TDD as i want to improve the quality of my code (design and structure) - reducing coupling, while at the same time hopefully reduce number of regressions which slip through to a testable build. I have taken a relatively simple project i work on to begin with. The resultant program watches a folder and then acts on files within this folder.

How to use Core Data for Dependency Injection

佐手、 提交于 2019-12-04 10:47:30
I'm toying with using Core Data to manage a graph of objects, mainly for dependency injection (a subset of the NSManagedObjects do need to be persisted, but that isn't the focus of my question). When running unit tests, I want to take over creation of the NSManagedObjects, replacing them with mocks. I do have a candidate means of doing this for now, which is to use the runtime's method_exchangeImplementations to exchange [NSEntityDescription insertNewObjectForEntityForName:inManagedObjectContext:] with my own implementation (ie. returning mocks). This works for a small test I've done. I have