Linked Questions

1
vote
1answer
193 views

Should I cover code that should not be able to fail with tests?

I'm asking myself above question since I implemented an API that accesses a third-party API and currently write tests to increase my code coverage in the class that communicates with the third-party ...
8
votes
4answers
3k views

How Should I Unit Test A Data Transfer Object?

Consider the following sample C# Data Transfer Object (DTO): public class MailingAddress { public string StreetAddress {get; set;} public string City {get; set;} public string ...
25
votes
3answers
14k views

Why would you write unit-tests for controllers?

To me this is a totally irrelevant unit-test and I don't understand why someone would spent time writing it, since there is very little value to gain from it. I would know perfectly well if this ...
4
votes
3answers
608 views

Purpose of unit testing simple methods

I'm trying out unit testing to see if it works for me, but im having trouble with these little functions. public void OpenNewMenuItem(MenuItemID ID, ITab DataContext = null){ var menuItem = ...
0
votes
1answer
874 views

Do I need to unit test a generic method with all accepted types?

For a method whose signature looks like this: public T Add<T>(T first, T second) where T : struct, IEquatable<T>, IComparable<T> which can work with all of the integral types, do I ...
0
votes
1answer
210 views

Is this wrapper class too simple to test?

I have a following class in my PHP code: <?php declare(strict_types=1); use function Http\Response\send; use Psr\Http\Message\ResponseInterface; class ResponseSender implements ...
1
vote
3answers
294 views

Are unit tests needed for a function that only calls another function?

Assuming OldModule.oldFunc, if we want to move oldFunc to NewModule and, for backward compatibility, keep oldFunc there merely calling NewModule.newFunc by passing the exact same arguments and doing ...
-1
votes
5answers
2k views

Is it good practice to have a unit test for a simple data method?

I have a simple data method that does this: public void Write(Foo foo) { db.Foos.Add(foo); db.SaveChanges(); } I was asked to write unit tests for this. To do so, I had to create a fake ...
1
vote
4answers
509 views

Little value in unit-testing the database component

Having a component that represents the database is wonderful! You can use it from the business logic to read and write data. But should that component be unit-tested? I would argue that it should ...
0
votes
1answer
180 views

How to test this getRandom() method? [duplicate]

There are strings and each string has a weight in a data structure. The getRandom() method should return a string randomly with its weight/total weight probability. There is already a question on how ...
17
votes
9answers
48k views

Should one test the values of an enum using unit tests?

If you have an enum with values only (no methods as one could do in Java), and this enum is part of the business definition of the system, should one write unit tests for it? I was thinking that they ...
1
vote
2answers
910 views

Test a wrapper to external static/singleton

I am integrating an external library that declares a singleton, like this: public class External : MonoBehaviour { public static External Instance { get {/*setup inner stuff*/} } public void ...
2
votes
2answers
4k views

How should I unit test a function that uses setters?

I'm using a repository pattern design and I've hit a stumbling block when writing a unit test for one of my methods. I'm fairly new to writing unit tests, so I would appreciate any help! Let's say I ...
0
votes
2answers
591 views

Should I test the aspects that type checking covers?

For example, should I test like this: // it shouldn't even compile since I'm using a static type-checking expect(addTen('string')).toThrowError() when it is already type-checked like this: function ...
7
votes
1answer
983 views

To what extent should I test what should not happen

In the case of unit testing, I'm testing as many cases as I can that when I do X, Y happens. I'm also concerned in some cases that when I do X, Z does not happen. But for the sake of protection, I ...
3
votes
1answer
177 views

Should I be unit testing “non dynamic” properties? [duplicate]

There is an ongoing debate about the following property, and if it should be tested or not. We're working in C#. MyClass prop => value; Should I be writing the following unit test : IMyClass ...
2
votes
1answer
601 views

When is interaction testing (invocation verification) while unit testing considered excessive?

I am under the impression that interaction testing (verifying mock invocations) in general should be avoided. When unit testing method postconditions should be asserted instead. However there are ...
4
votes
0answers
161 views

unit testing a mocked class [duplicate]

I'm currently writing unit tests for my PHP code. I've read that unit tests should not interract with external elements such as network and filesystem. In my code i have a curl wrapper class to ...
71
votes
10answers
25k views

Should we test all our methods?

So today I had a talk with my teammate about unit testing. The whole thing started when he asked me "hey, where are the tests for that class, I see only one?". The whole class was a manager (or a ...
13
votes
2answers
3k 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
1answer
4k views

Is it worth writing a unit test for a DTO with the most basic getter/setters? [duplicate]

The advantage is it protects your DTO against future "enhancements" ?