tdd

How to write testable controllers with private methods in AngularJs?

假如想象 提交于 2019-11-28 15:42:48
Alright, so I have been stumbling upon some issue for a long time and I would like to hear an opinion from the rest of community. First, let's look at some abstract controller. function Ctrl($scope, anyService) { $scope.field = "field"; $scope.whenClicked = function() { util(); }; function util() { anyService.doSmth(); } } Clearly we have here: regular scaffold for controller with $scope and some service injected some field and function attached to the scope private method util() Now, I'd like to cover this class in unit tests (Jasmine). However, the problem is that I want to verify that when

BDD with Cucumber and rspec - when is this redundant?

一笑奈何 提交于 2019-11-28 15:28:51
A Rails/tool specific version of: How deep are your unit tests? Right now, I currently write: Cucumber features (integration tests) - these test against the HTML/JS that is returned by our app, but sometimes also tests other things, like calls to third-party services. RSpec controller tests (functional tests), originally only if the controllers have any meaningful logic, but now more and more. RSpec model tests (unit tests) Sometimes this is entirely necessary; it is necessary to test behavior in the model that is not entirely obvious or visible to the end-user. When models are complex, they

What not to test when it comes to Unit Testing?

懵懂的女人 提交于 2019-11-28 15:23:29
问题 In which parts of a project writing unit tests is nearly or really impossible? Data access? ftp? If there is an answer to this question then %100 coverage is a myth, isn't it? 回答1: Here I found (via haacked something Michael Feathers says that can be an answer: He says, A test is not a unit test if: It talks to the database It communicates across the network It touches the file system It can't run at the same time as any of your other unit tests You have to do special things to your

How do you unit test regular expressions?

天大地大妈咪最大 提交于 2019-11-28 15:21:08
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? Robert P 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 design, but some guidelines to shape your thinking. As always, weigh the needs of your testing

What are the best practices for testing “different layers” in Django? [closed]

送分小仙女□ 提交于 2019-11-28 15:12:47
I'm NOT new to testing, but got really confused with the mess of recommendations for testing different layers in Django. Some recommend (and they are right) to avoid Doctests in the model as they are not maintainable... Others say don't use fixtures , as they are less flexible than helper functions , for instance.. There are also two groups of people who fight for using Mock objects. The first group believe in using Mock and isolating the rest of the system, while another group prefer to Stop Mocking and start testing .. All I have mentioned above, were mostly in regards to testing models.

When to rewrite a code base from scratch

一笑奈何 提交于 2019-11-28 15:10:46
I think back to Joel Spolsky's article about never rewriting code from scratch. To sum up his argument: The code doesn't get rusty, and while it may not look pretty after many maintenance releases, if it works, it works. The end user doesn't care how pretty the code is. You can read the article here: Things You Should Never Do I've recently taken over a project and after looking through their code, it's pretty awful. I immediately thought of prototypes I had built before, and explicitly stated that it should not be used for any production environment. But of course, people don't listen. The

Why use JUnit for testing?

孤者浪人 提交于 2019-11-28 15:07:54
Maybe my question is a newbie one, but I can not really understand the circumstances under which I would use junit ? Whether I write simple applications or larger ones I test them with the System.out statements and it seams quite easy to me. Why create test-classes with JUnit, unnecessary folders in the project if we still have to call the same methods, check what they return and we then have an overhead of annotating everything? Why not write a class and test it at once with System.out but not create Test-classes? PS. I have never worked on large projects I am just learning. So what is the

TDD vs. Unit testing [closed]

此生再无相见时 提交于 2019-11-28 15:02:14
My company is fairly new to unit testing our code. I've been reading about TDD and unit testing for some time and am convinced of their value. I've attempted to convince our team that TDD is worth the effort of learning and changing our mindsets on how we program but it is a struggle. Which brings me to my question(s). There are many in the TDD community who are very religious about writing the test and then the code (and I'm with them), but for a team that is struggling with TDD does a compromise still bring added benefits? I can probably succeed in getting the team to write unit tests once

Can unit testing be successfully added into an existing production project? If so, how and is it worth it?

天大地大妈咪最大 提交于 2019-11-28 14:56:37
I'm strongly considering adding unit testing to an existing project that is in production. It was started 18 months ago before I could really see any benefit of TDD (face palm) , so now it's a rather large solution with a number of projects and I haven't the foggiest idea where to start in adding unit tests. What's making me consider this is that occasionally an old bug seems to resurface, or a bug is checked in as fixed without really being fixed. Unit testing would reduce or prevents these issues occuring. By reading similar questions on SO, I've seen recommendations such as starting at the

Is there hard evidence of the ROI of unit testing?

谁说胖子不能爱 提交于 2019-11-28 14:56:14
Unit testing sounds great to me, but I'm not sure I should spend any time really learning it unless I can convince others that is has significant value. I have to convince the other programmers and, more importantly, the bean-counters in management, that all the extra time spent learning the testing framework, writing tests, keeping them updated, etc.. will pay for itself, and then some. What proof is there? Has anyone actually developed the same software with two separate teams, one using unit testing and the other not, and compared the results? I doubt it. Am I just supposed to justify it