tdd

Are PHP global constants a good modern development practice?

可紊 提交于 2019-12-05 12:05:37
问题 I'm working on a new project with a sizeable PHP codebase. The application uses quite a few PHP constants ( define('FOO', 'bar') ), particularly for things like database connection parameters. These constants are all defined in a single configuration file that is require_once() 'd directly by basically every class in the application. A few years ago this would have made perfect sense, but since then I've gotten the Unit Testing bug and this tight coupling between classes is really bothering

Unit testing algorithms that involve random numbers

拈花ヽ惹草 提交于 2019-12-05 11:56:14
I'm writting some code about fractals and random terrain generation. Specifically, I'm using the Diamond-Square algorithm as of now. For those of you who don't know, it basically obtains the average of four values, and adds a random number, every step. How wouldI go about testing the result? Should I use a known seed and calculate by hand the average plus the random value, or what? Should I, instead, calculate the result in the code, using the random numbers? Or is there another way? Also, some thought on the reverse process (a.k.a. TDD, writting tests before code) would be much appreciated).

Should I never use static methods and classes and singletons when following the Test Driven Development paradigm

你。 提交于 2019-12-05 10:52:35
问题 I've been reading that static methods, static classes, and singletons are evil when you try to implement unit testing in your project. When following the TDD paradigm, should I just forget that they ever existed and never use them again or is it ok to use them sometimes? 回答1: Never say never--static classes and methods have their place in your toolbox. That said, if the class you are trying to isolate and test (subject under test or SUT) depends on a static class or method, you will be unable

How to efficiently JUnit test Eclipse RCP Plugins

廉价感情. 提交于 2019-12-05 10:36:15
We have a rather larger Eclipse RCP application and are not sure how to properly test it's plugins. For each plugin, there is a test fragment that contains Unit tests. For smaller tests, that do not require the RCP Platform running, we simply invoke the "standard" JUnit test runner. For tests, that require the RCP Platform, there is the possibility to test it using the JUnit plugin test runner. For the JUnit plugin tests, it is possible to define which plugins are loaded when the RCP Platform starts up. Problem : Running JUnit Plugin Tests takes a lot of time (seconds instead of millicseconds

Proper unit testing technique

為{幸葍}努か 提交于 2019-12-05 10:34:01
While Using TDD I found myself needing to test a constant (final) hashmap which contains lookup values ( PLEASE SEE REASON WHY THIS WAS THE CASE UNDER UPDATE ) See below private static final Map<Integer,String> singleDigitLookup = new HashMap<Integer, String>(){{ put(0,"Zero");put(1,"One");put(2,"Two");put(3,"Three");put(4,"Four");put(5,"Five");put(6,"Six");put(7,"Seven"); put(8,"Eight");put(9,"Nine"); }}; With TDD its stressed to test one thing at a time so i started calling my class verifying the validity of each of the elements as below. TEST STYLE 1 @Test public void

Have you been in cases where TDD increased development time?

喜你入骨 提交于 2019-12-05 10:26:13
I was reading TDD - How to start really thinking TDD? and I noticed many of the answers indicate that tests + application should take less time than just writing the application. In my experience, this is not true. My problem though is that some 90% of the code I write has a TON of operating system calls. The time spent to actually mock these up takes much longer than just writing the code in the first place. Sometimes 4 or 5 times as long to write the test as to write the actual code. I'm curious if there are other developers in this kind of a scenario. In general, when people have the

How to handle the refactoring phase of TDD

夙愿已清 提交于 2019-12-05 09:52:41
In the course of a TDD session, suppose I write a failing test, and then make it pass. I refactor by extracting code out of the original Unit, using refactorings such as Extract Class and Move Method. Now further suppose that my original test no longer covers the extracted code because the original code now mocks out its dependencies, as is correct for a Unit test. Is it proper to go back and retrofit tests onto the extracted code? Or did I make a mistake in how I ended up with untested code during a refactoring? It feels like as my codebase is scaling, and I have to refactor, I'm retrofitting

How to keep rspec tests DRY with lots of “have_link”

99封情书 提交于 2019-12-05 09:47:47
I'm new to Ruby on Rails and I'm doing http://ruby.railstutorial.org right now. From what I understand the language is supposed to follow this DRY standard wery strictly but it's so WET when it comes to test driven development in this tutorial. For example it { should have_link('Users', href: users_path) } it { should have_link('Profile', href: user_path(user)) } it { should have_link('Settings', href: edit_user_path(user)) } it { should have_link('Sign out', href: signout_path) } Here we have lots of rows that almost looks the same. I'we tried this it "should have following links from this

How Can I Add a Unit Test Project to an Existing MVC3 Application (from empty template)

妖精的绣舞 提交于 2019-12-05 09:16:06
问题 I created an MVC3 application from the Empty template so I couldn´t add a Visual Studio Unit test project to the solution. I made some changes, added some controllers and now I want to try TDD so I need to add a framework for testing. But I can´t see how I can do that. I want some way where I can create my test project right in the Solution Explorer, for example "website.Test" with some basic folders and files. I saw here some questions about how to add Unit tests, but those were with xUnit

Can phpunit use multiple data provider

浪子不回头ぞ 提交于 2019-12-05 08:53:32
问题 One question in short: can phpunit use multiple data provider when running test? For example, I have a method called getById, and I need to run both successful and unsuccessful testcases for it. The successful testcases means that it can return a corresponding record. And for the unsuccessful, the input can fall in two categories: invalid and failed. The invalid means that the input is not legal, while failed means the input could be valid, but there is no corresponding record with that ID.