Unit testing is a method by which individual units of source code are tested to determine if they are fit for use.

learn more… | top users | synonyms (1)

0
votes
0answers
20 views

What kind of tests should be written for database-centric web-app?

What kind of tests should be written for database-centric web-app ? Is there any point in writing junit tests and mocking database ?
1
vote
1answer
48 views

Testing Facades, Is it a good idea?

I stumbled across a need to create a thin I/O Layer interface to abstract away a class from the need to know about I/O public interface IFileIOProvider { Task WriteFileAsync(String contents, ...
3
votes
7answers
541 views

Why don't I see many unit test projects that bring up and tear down a DB? (ASP.NET MVC)

I see all the examples that demonstrate unit testing code and mocking the calls to the DB since you are not suppose to touch the DB. But it seems to me having a set up tasks that uses the actually ...
32
votes
13answers
3k views

Unit-testing of inherently random/non-deterministic algorithms

My current project, succinctly, involves the creation of "constrainably-random events". I'm basically generating a schedule of inspections. Some of them are based on strict schedule constraints; you ...
2
votes
1answer
63 views

Testing gap between unit and integration: Integration in the Small, Component, Unit Integration Tests

Over the past few weeks I've been mulling and researching how to fill a gap in our testing methodology. In simplified terms unit tests are too small and traditional integration tests are too big. A ...
28
votes
6answers
3k views

Why isn't testing a language a supported feature at the syntax level?

You can find an endless list of blogs, articles and websites promoting the benefits of unit testing your source code. It's almost guaranteed that the developers who programmed the compilers for Java, ...
17
votes
4answers
688 views

How can I use unit tests and TDD to test an app that relies mostly on database CRUD operations?

At work, one of my projects is mostly about taking data passed in from an external client and persisting it in a database. It's a Java enterprise app using JPA and most of our logic revolves around ...
3
votes
3answers
282 views

Is it feasible and useful to auto-generate some code of unit tests?

Earlier today I have come up with an idea, based upon a particular real use case, which I would want to have checked for feasability and usefulness. This question will feature a fair chunk of Java ...
0
votes
3answers
179 views

How should I test boolean function with many possible permutations

When I write an unit test I usually provide a context (plain object or mocked/stubbed object) that I setup in some ways and then I can run assert statement on the context: note: code is in ...
11
votes
7answers
464 views

Coding and testing in the same sprint

How is testing handled within the same sprint as coding, if all or most of the coding is not done until the end of the sprint? (I'm referring to the "soup-to-nuts" development and testing of a single ...
1
vote
1answer
483 views

scons and python unit tests best practices

I am using scons to build a large project containing a mix of C++ and Python. I would like scons to run Python unit tests either using nose or not. Currently, we have a long list of tests files and ...
3
votes
2answers
337 views

What is the most appropriate testing method in this scenario?

I'm writing some Objective-C apps (for OS X/iOS) and I'm currently implementing a service to be shared across them. The service is intended to be fairly self-contained. For the current functionality ...
-1
votes
1answer
110 views

Approach to cover all the cases in Unit Tests [duplicate]

I am new to Unit Testing and i am able to write them but my problem is I am not sure that I have covered everything in Unit Tests. What could be the approach for testing some functionality in a code?
4
votes
3answers
460 views

Should unit test be in separated repository?

Should I put unit testing stuffs in a separate repository, not in the same repository as the programming library? So I reference the programming library as submodule. But most open source projects ...
0
votes
1answer
114 views

In an enterprise setting, does one apply BDD principles alongside of, or instead of, “traditional” unit testing?

I have a problem visualising how the gap is closed between coarse-grained, n-tier boundary, high level, automated acceptance testing and lower level, task/sub-task scope Unit Testing. My motivation ...
3
votes
4answers
445 views

Is spying on tested class bad practice?

I am working on a project where class internal calls are usual but the results are many times simple values. Example (not real code): public boolean findError(Set<Thing1> set1, ...
4
votes
3answers
162 views

How should I unit test a bitmap modifying method?

My Sprite class has a method: private void updateWithBitmap(Bitmap b, int x, int y) This will 'lay on top' the bitmap that's passed in, the top left corner of the passed in bitmap being at the x,y ...
2
votes
1answer
73 views

Should “tests” be kept out of the main merge pipeline?

We all know sometimes a e.g. merge can go wrong. If our [unit / integration] tests are in the same repository as the merge, is there then a weakness there that if the tests have merged incorrectly ...
0
votes
2answers
266 views

Is there a better way to organize my module tests that avoids an explosion of new source files?

I've got a neat (so I thought) way of having each of my modules produce a unit-test executable if compiled with the -DTESTMODULE flag. This flag guards a main() function that can access all static ...
24
votes
3answers
2k views

Are asserts or unit tests more important?

Both asserts and unit tests serve as documentation for a codebase, and a means of discovering bugs. The main differences are that asserts function as sanity checks and see real inputs, whereas unit ...
4
votes
2answers
137 views

Unit testing - one test is partly a “superset” of another, is this wrong?

Wasn't sure how to phrase that title, sorry! I've just come across this in our code base, and was wondering what the consensus was about how to unit test it: C# (-ish, sorry, this is paraphrased ...
4
votes
2answers
213 views

What kind of code would Kent Beck avoid unit testing? [duplicate]

I've been watching a few of the Is TDD Dead? talks on youtube, and one of the things that surprised me is Kent Beck seems to acknowledge that there are just some kinds of programs that aren't worth ...
1
vote
2answers
64 views

Creating an Interface To a Language's Standard Library?

In the process of learning test-driven development, I've been introduced to dependency injection and the use of interfaces, and have started using these concepts in my own PHP code in order to make it ...
0
votes
1answer
109 views

Your thoughts on Best Practices for Scientific Computing? [closed]

A recent paper by Wilson et al (2014) pointed out 24 Best Practices for scientific programming. It's worth to have a look. I would like to hear opinions about these points from experienced programmers ...
0
votes
1answer
101 views

Is the test, which touches the filenames under directory, a kind of unittest? [closed]

I was told that unittest is fast and the tests which touches DB, across network, and touches FileSystem are not unittest. In one of my testcases, its input are the file names (amount about 300~400) ...
62
votes
10answers
4k views

Does it make sense to write tests for legacy code when there is no time for a complete refactoring?

I usually try to follow the advice of the book Working Effectively with Legacy Code. I break dependencies, move parts of the code to @VisibleForTesting public static methods and to new classes to make ...
0
votes
1answer
66 views

How to unit test models in MVC / MVR app?

I'm building a node.js web app and am trying to do so for the first time in a test driven fashion. I'm using nodeunit for testing, which I find allows me to write tests quickly and painlessly. In this ...
4
votes
3answers
327 views

Inheritance vs containment while extending a large legacy project

I have got a legacy Java project with a lot of code. The code uses MVC pattern and is well structured and well written. It also has a lot of unit tests and it is still actively maintained (bug fixing, ...
10
votes
2answers
409 views

How do you unit test your javascript

I spend a lot of time working in javascript of late. I have not found a way that seems to work well for testing javascript. This in the past hasn't been a problem for me since most of the websites I ...
9
votes
6answers
478 views

How to use unit tests as a source of information?

A colleague of mine was once at a seminar about agile development, where he heard it is possible to use unit tests as technical documentation. Something like using unit tests as an example of how to ...
2
votes
1answer
98 views

Separate Action from Assertion in Unit Tests

Setup Many years ago I took to a style of unit testing that I have come to like a lot. In short, it uses a base class to separate out the Arrangement, Action and Assertion of the test into separate ...
1
vote
2answers
158 views

Scenario to illustrate how unit testing leads to better design [closed]

For an internal training session, I'm trying to come up with a simple scenario that illustrates how unit testing leads to better design, by forcing you to think about things like coupling before you ...
1
vote
3answers
439 views

Unit Testing Wrapper (Facade?) Method

I have to write unit tests for some classes my group is developing. The classes are fairly simple, and I'm not sure how to best test them. public class MyObjectRegistry { private ...
0
votes
1answer
71 views

How to write a good mock for testing

I code in Python and I'm starting to use the Mock library. Although I've read through all of the documentation, something that I'm finding hard to understand is 'What makes a good mock'. For ...
8
votes
3answers
336 views

Designing unit tests for a stateful system

Background Test Driven Development was popularized after I already finished school and in the industry. I am trying to learn it, but some major things still escape me. TDD proponents say lots of ...
0
votes
1answer
104 views

How do you detect lying Stubs/Mocks?

Consider this piece of code from the PHPUnit manual(I'm using PHP only as an example): class StubTest extends PHPUnit_Framework_TestCase { public function testStub() { // Create a ...
3
votes
3answers
131 views

Using 2 Constructors: one that injects dependencies and one that instantiates them

I started using TDD for the first time on a project I started recently. I have a few objects with dependencies and structures that look something like this: public class MyClass { private ...
1
vote
2answers
129 views

How to unit test without mocks and not be tied to a concrete implementations of an interface

I consider myself to be a 'mockist' on the 'mockist' vs 'classicist' debate, but I am trying to understand the other point of view. Imagine I have this class, where a concrete instance of IDependency ...
2
votes
2answers
270 views

How to unit test code which is intended to have different results on different platforms

I noticed some duplicate code in a codebase I am working on that appended a filename to a directory path, so I decided to refactor it into its own method. The application I am working on is not well ...
1
vote
4answers
100 views

Looping Exhaustive Test Cases - A Good Practice?

Sometimes we have code like this: private static final List<Goat> INEDIBLE_GOATS = [GOAT_A, GOAT_B, GOAT_C] void eatGoat(Goat goat) { if(INEDIBLE_GOATS.contains(goat)) { throw new ...
0
votes
0answers
51 views

What is a good method of storing test data for development and unit testing with angular and jasmine?

What is a good method of storing JSON data/objects for development and unit testing with angular and jasmine? I have seen some ways of accomplishing this. However, since I am new to unit testing with ...
2
votes
2answers
477 views

Should I bother to write unit test for UI/UX Components?

So I am building an application with Angular and have started to get into UI testing with DalekJS (http://dalekjs.com). As I have been writing these tests I have been thinking to myself, should I ...
7
votes
3answers
997 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? ...
3
votes
0answers
76 views

How do you prevent confused tests? [duplicate]

Testing code for correctness is important. Whether you do strict TDD or not, tests are really the only way a project can scale in size beyond a point where every team member can reasonably keep all ...
0
votes
1answer
96 views

Unit-based architecture

This is probably a damn fool question, for which I apologise, but I can't seem to get the google syntax right to find an answer. Imagine a Property, like this: private int _type public int Type { ...
-2
votes
3answers
157 views

How to show to management that unit testing is cheaper in the long run than manual testing? [duplicate]

In the company I work for there is a requirement that all the code should be covered by a test of any kind because they want to have as few user reported defects as possible. With this is mind I ...
6
votes
3answers
1k views

What is the best practice for refactoring a static method in order to make it more testable?

Let's say you have a static method that looks something like this: public static bool Foo() { var bar = new Bar(); //do some stuff here } This method as it stands can be a real headache to ...
1
vote
4answers
147 views

Help in ensuring unit tests are meaningful

I've just written a unit test for this function, which loops through a collection of dates and sets properties equal to true or false depending on whether they're before or after a given comparison ...
13
votes
3answers
3k views

Should I still use Debug.Assert today?

I recently came across some newly written code that was interspersed with lots of Debug.Assert (C#). Should we still use this widely despite the usage of TDD, BDD and Unit Testing in general?
0
votes
3answers
79 views

Is it good style to check explicitly for null in unit tests?

Whether or not a value is null could be checked implicitly like this: assertThat(value).isEqualTo("something"); Or it could be checked explicitly: assertThat(value).isNotNull(); ...