Questions tagged [unit-test-data]
9 questions
19
votes
2 answers
To load or not to load data for unit tests from external files
When unit testing I often find myself debating how much of the data I feed to, and expect back from my units under test, I should include in the actual test files.
The tradeoff I constantly struggling with is:
If a large portion of the test (in…

DudeOnRock
- 1,079
- 10
- 21
5
votes
2 answers
Unit tests tactics
The only unit tests tactic I'm familiar with is comparing against golden data _ a predefined set of input data for which output is known (preferably including corner cases).
I cannot think of any other reasonable way of unit testing. Trying to unit…

superM
- 7,363
- 4
- 29
- 38
4
votes
2 answers
Does one need to mock concrete data objects?
I've been working on a large project where much of the code is not under test. I have been able to add some unit tests to functional areas of the code, and also to start mocking services but I have a question about how much mocking to do on other…

Zach Leighton
- 131
- 9
3
votes
2 answers
Is it acceptable to test based on test output data rather than input data in unit tests?
I'm used to write unit tests with assertions which are based on the input, e.g. (hopefully self-explanatory and let's assume that using random test data is fine)
int a = random();
int b = random();
Adder instance = new Adder();
int expResult =…

Kalle Richter
- 222
- 1
- 7
2
votes
3 answers
Using methods that are not under test within a unit test for a different method?
I'm building a Sudoku generator. I have a board class with a number of methods:
public class Board {
public Board() { /* Creates an empty board */ }
public bool ValidateRow(int row) { /* Checks for errors in row */ }
public bool…

Shaun Hamman
- 131
- 4
2
votes
3 answers
Reading a file before testing a method - it is an integration test or a unit test?
Let's say I write a parser. It takes an argument that is a String and does something with that. This String can be very long so keeping it in a test class can dirty my code. I think that it would be better to keep this String in a file and read it…

tdudzik
- 141
- 3
0
votes
1 answer
Unit/Component testing using In Memory DB
I am writing Unit/Component test using In Memory DB. When I write Unit/Component test, I came across with the following question.
I have the following two BL methods.
ToCreate
ToGet
So when I write Unit/Component test, I need to create some…

Jeeva Jsb
- 101
- 4
-1
votes
1 answer
Best practices on unit tests for consecutive functions
Let's say we have function A and function B which perform consecutive operations on some data, with B never receiving the data before A processes it.
Function A makes exhaustive checks on potential errors on the input data. For A, it's a no-brainer…

Paul Razvan Berg
- 125
- 4
-4
votes
1 answer
Unit testing data-transformation functions that call external APIs
Lets say you have a class that has the responsibility producing a set of finished data, but the method of producing that data is intentionally an implementation detail and as such should be left inaccessible to clients. How do you unit test such an…

Darinth
- 127
- 7