Questions tagged [unit-testing]
Unit testing is a method by which individual units of source code are tested to determine if they are fit for use.
1,731
questions
27
votes
8
answers
33k
views
How do I unit test a web forms site?
How do I unit test a web forms site? It seems to me that as so much of it depends on state and user input it wouldn't be feasible.
If it's not feasible is there a valid automated alternative?
14
votes
4
answers
6k
views
Why use phpunit when traditional manual testing can be used
When I make a web app I test my work on the browser to see if I receive any errors and fix them. I have made complex applications and testing this way has been easy and fast. I have watched many ...
15
votes
5
answers
7k
views
When you should and should not use the 'new' keyword?
I watched a Google Tech Talk presentation on Unit Testing, given by Misko Hevery, and he said to avoid using the new keyword in business logic code.
I wrote a program, and I did end up using the new ...
23
votes
7
answers
2k
views
Does adding unit tests make sense for well-known legacy code?
I'm talking about unit tests in the TDD sense. (Not automated "integration", or what you like to call it tests.)
Legacy code as in: (C++) code without tests. (see: Michael Feathers' Working ...
0
votes
4
answers
2k
views
How do I convince some one that test should do assertion (not assertions) and not the helper methods
Joined a new employer and came across a new style of writing tests.
@Test()
public testMethodWhichDoesNotDoAnyAssertion() {
LoginPage loginPage = signUpPage.doLogin("username","password");
...
9
votes
3
answers
940
views
Ramping Up On Legacy Code [duplicate]
When starting to work on a project with an existing code base, the first thing that needs to be done is usually to understand the application & existing code. Let's assume that the existing code ...
3
votes
3
answers
428
views
How to keep settings for C++ Unit Test modules in sync with the production code modules?
Note: I'm coming from a Windows / Visual-C++ background.
Note: I have already read Michael Feathers' Working Effectively with Legacy Code.
Note: Broad question, asking for narrow answers, i.e. while I ...
5
votes
4
answers
157
views
How are dates typically handled with testing?
I am writing an app at the moment that has some pretty extensive business logic based around dates. I have several hundred thousand records to test and testers who want to see how those records are ...
8
votes
1
answer
2k
views
Unit testing of "workflow" methods
We are currently developing a public API for our app. The methods on this public API are mostly putting together functionality in different corners of the system.
An example would be: (names have been ...
8
votes
3
answers
5k
views
Agile development deployment process. Where do QA and Business Owners test?
I've been reading up a lot lately on various web application deployment processes using SVN or GIT, with a view to redesigning how we currently deploy where I work.
As is the way with many flavours ...
3
votes
3
answers
1k
views
On the effectiveness of unit testing
How effective are unit tests in reality?
I am under the impression that at some point unit tests turn into tests that test the dependency between the object under test and another object. Sure, one ...
10
votes
3
answers
2k
views
Do we need test data or can we rely on unit tests and manual testing?
We're currently working on a medium/large PHP/MySQL project. We're doing unit testing with PHPUnit & QUnit and we have two full time testers that are manually testing the application. Our test (...
0
votes
1
answer
77
views
Verification naming confusion
According to Martin Fowler classical article, there are two types of verification: state and behaviour verification. At the same time I often see people telling about implementation vs. behaviour ...
4
votes
2
answers
1k
views
Does a project using proper TDD have a lot of code without tests?
Most (all?) TDD resources show you how the cycle goes:
Write Test
Check Test
Write Production Code
Check Test
Clean up Production Code
Check test
They also - to me - seem to imply that all code is ...
25
votes
5
answers
23k
views
What's the best way to organize our unit tests
We've built up a substantial number of unit tests for our main program over the years. Several thousand. The problem is that we don't have a clear idea of what tests we have because there are so many. ...
16
votes
4
answers
4k
views
Does test-driven development force me to follow SOLID?
I hear a lot from TDD practitioners that one of TDD's advantages is that it forces developers to follow SOLID principles (Single responsibility, Open-closed, Liskov substitution, Interface segregation ...
7
votes
6
answers
3k
views
What are the advantages to BDD for a solo developer?
I have found this lines below about the advantages of BDD (Behavior Driven Development)
The domain experts define what they need in the program in a way that
the developers can not misinterpret (...
12
votes
3
answers
6k
views
Understanding Cyclomatic Complexity
I've recently come across Cyclomatic Complexity and I'd like to try to understand it better.
What are some practical coding examples of the different factors that go into calculating the complexity? ...
10
votes
3
answers
2k
views
Unit testing methods that call suppliers webservices
I have a class with one public method Send() and a few private methods. It calls a couple of webservices and processes the reponse. The processing is done in private methods.
I want to unit test the ...
21
votes
5
answers
5k
views
How granular should TDD tests be?
During TDD training based on medical software case we are implementing the following story: "When user presses Save button, system should add patient, add device and add device data records".
The ...
11
votes
3
answers
22k
views
Writing java doc comments for unit test cases
In my opinion, the unit test cases itself serve as a documentation for the code. My company wants me to write detailed java doc comments on top of unit test cases. Is it necessary to do so? Do you ...
27
votes
8
answers
6k
views
How to Avoid Fragile Unit Tests?
We have written close to 3,000 tests -- data has been hard coded, very little reuse of code. This methodology has began to bite us. As the system changes we find ourselves spending more time fixing ...
12
votes
3
answers
2k
views
Automating Unit Test Creation
What are some strategies that could be used to automate the creation of unit test cases? What aspects would you need to look at in each class to be able to generate at least a decent test case ...
5
votes
6
answers
3k
views
Is there any value in knowing the execution time for a unit test?
Is the execution time of a unit test useful for anything? Is a unit test an appropriate place for any sort of code profiling? Why or why not?
Sample Use Case:
Every unit test lists name, pass/fail, ...
5
votes
1
answer
934
views
Integration tests across a 3-tier .NET solution
I have a 3-tiered .NET solution.
Database (SQL SERVER 2008)
Web Service (SOAP Service - *.asmx)
WPF Client
I am comfortably writing Unit Tests within (3) The Client.
I am currently working on ...
22
votes
3
answers
11k
views
Is it okay to fake part of the class under test?
Suppose I have a class (forgive the contrived example and the bad design of it):
class MyProfit
{
public decimal GetNewYorkRevenue();
public decimal GetNewYorkExpenses();
public decimal ...
8
votes
3
answers
717
views
Should I unit test
Most of the logic for my webservice involves talking to our supplier's webservices (checking availability, ordering etc.) They don't have a test environment and the majority of calls can't be run ...
20
votes
7
answers
974
views
What can you do about the quality of existing integration and unit tests while being the new guy in a team ?
A recurring theme that I came across in my career is being the new developer to arrive in a team, and quickly having an inherent distrust of the existing unit and integration test suites.
During the ...
15
votes
4
answers
2k
views
How to Quantify the Value of Unit Testing [duplicate]
Our organization is considering integrating unit testing into our software development workflow. I've heard lots of anecdotal stories about how it encourages better, easy to maintain, and well-planned ...
6
votes
2
answers
774
views
Writing functional tests for a legacy project
I am trying to add a couple of tests to a legacy C project. The project basically consists of a command line tool that prints something to stdout every time an event happens. Now, since writing unit ...
7
votes
6
answers
1k
views
"Anything can go wrong will go wrong" - Murphy's Law. so is it necessary to test all the conditional, exception cases? [closed]
If "Anything can go wrong will go wrong" is true, we need to test all the conditionals and exceptional cases in my code.
But sometimes it's hard to find all of them since many of them are corner ...
52
votes
2
answers
11k
views
How should C++ Unit Test code be organized for maximum Unit Test efficiency?
This question is not about Unit Testing Frameworks.
This question is not about writing Unit Tests.
This question is about where to put the UT code written and how/when/where to compile and run it.
...
11
votes
3
answers
412
views
Videos on Unit Testing [closed]
I've been searching for good presentations (slides+audio or video preferred) on Unit Testing but all I seem to find are books and blog posts. The presentation should not be longer than 50 minutes ...
12
votes
5
answers
7k
views
Are RSpec and Cucumber really worth it?
I know most RoR programmers are testing addicts and I understand the advantages of a large testing suite but when I start testing, I never get such a large suite and I always wonder "Am I testing the ...
48
votes
7
answers
25k
views
best practice when unit testing for embedded development
I am looking for some best practice strategies for unit testing code written for embedded system. By embedded system, I mean code such as device drivers, ISR handlers etc., stuff that are pretty close ...
6
votes
6
answers
2k
views
Should Unit Testing be used in Prototypes?
When constructing prototypes, should we also create appropriate unit tests as if we were writing production code? Would it make a difference if we knew in advance that the code was or wasn't going to ...
13
votes
2
answers
2k
views
Adding unit tests to a legacy, plain C project
The title says it all. My company is reusing a legacy firmware project for a microcontroller device, written completely in plain C.
There are parts which are obviously wrong and need changing, and ...
4
votes
1
answer
300
views
What is the typical Pythonic view on re-using python modules outside of their initial intent?
Short Question
Does it fly in the face of the Pythonic view to reuse / repurpose python modules for projects out side of their intent?
Background
Over the past several months I have been working on ...
22
votes
3
answers
42k
views
Should I use try catch in my test methods?
I am doing unit testing.
I am trying to test one function.
I call it from my test component. But If remote function cannot handle the exception then my tester component will also get exception, I ...
10
votes
3
answers
5k
views
Unit testing vs Integration Testing [duplicate]
What is the difference between unit testing and integration testing when it come to web development (where 90-95% of the code relies on a database)? One thing I here all the time is that unit testing ...
26
votes
6
answers
7k
views
Databases and Unit/Integration Testing
I have had a discussion with someone about unit/integration testing with web applications and I have a disagreement about 1 core idea. The issues is that the person I am talking to think that the ...
9
votes
4
answers
844
views
What is understood under "unit" in unit testing
As I understand in theory under "unit" people mean method (in OOP). But in practice tests which verify some method in isolation are very fragile behaviour tests (verifying not the result but the fact ...
290
votes
14
answers
426k
views
How do you unit test private methods?
I am working on a java project. I am new to unit testing. What is the best way to unit test private methods in java classes?
3
votes
2
answers
219
views
Do you write unit testing or TDD as a line item requirement into your contracts or statements of work?
If you do, do you discuss coverage, continuous integration, quality control, or anything related to the difference between unit testing, functional testing and TDD in general? If clients ask, do you ...
4
votes
3
answers
561
views
UnitTests, will cleaning up your act-statement make your test more or less clear?
Lets say that we are testing FooClass with the following method:
public void Foo(string stringParameter, int intParameter, Action<Bar> successCallback, Action<Exception> errorCallback)...
14
votes
5
answers
2k
views
Should one test for algorithmic complexity? If so, how?
Let's say I am implementing something simple like searching a sorted list/array. The function (in c#) would look similar to:
static int FindIndex(int[] sortedList, int i);
I could implement and test ...
14
votes
3
answers
1k
views
Orthogonality of unit tests vs. concision of unit tests
I'm writing unit tests for a steering system for a video game. The system has several behaviours (avoid this area because of reason A, avoid this area because of reason B, each adding a bit of context ...
37
votes
10
answers
4k
views
TDD - is it just about unit tests? [duplicate]
Do I understand it right that classical TDD is just about unit tests? Don't understand me wrong: I know the difference between TDD and just unit testing. I am asking whether it is correct to use ...
32
votes
6
answers
19k
views
how much time do you spend on Unit testing?
In a company I used to work for, executives insisted that the code coverage with unit tests must be 99% or more. This resulted in writing more tests than code. It took us literally 3 days to write ...
7
votes
3
answers
2k
views
Unit Testing For Different Environments
How does one do unit testing for multiple environments that behave differently?
Here is my problem. I have a PHP class for which I'd like to create unit tests. The class provides shortcuts for ...