Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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.

3
votes
1answer
443 views

Does using fixtures make a unit test an integration test?

Does using touching a database mean a unit test is an integration test even if you are using fixtures? If so, what are the alternatives to write a unit test when you need to use models as a part of a ...
3
votes
2answers
242 views

Test Internals with TDD?

I'm new to TDD, and relatively new to software development in general (e.g. < 4 years experience), but I am trying to learn. I have been toying with TDD but ran into what I know realize is a ...
3
votes
2answers
124 views

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(); ...
2
votes
5answers
320 views

Unit testing and other forms of testing

This may be a silly question but if I have good unit test coverage, does that mean I can reduce the amount of, or remove completely, functional and integration testing. When people talk about having a ...
2
votes
1answer
190 views

Is it a best practice to use a mocking service for testing http requests?

Is it better to unit test using a mock library like 'nock' (nodejs) or to just test the server's http requests directly? Here is an example of my Express server test for testing if my server is up ...
0
votes
1answer
96 views

What are the dangers/downside of unit tested dynamic library(DLL) being different from released library?

This is similar to: https://stackoverflow.com/questions/1278831/unit-tests-in-production-release-code# but more specific. At the moment the DLL I ship and the DLL I use for unit testing have ...
1
vote
2answers
163 views

Should I write integration test that test my code with real-network servers, before I start writing my code?

I am trying to write integration tests for a client-server app. The client app runs on a user's machine and connects to the server app running on a specific Windows server, network-serverA. The ...
2
votes
1answer
194 views

Making a test fixture inherit from the SUT class

Some time ago I had to code review a unit-test fixture like this one (C# code): public class ServiceFixture : Service { [Fact] public void Test_DoSomething() { Assert(DoSomething()...
0
votes
1answer
167 views

Design Pattern for doing things in sequence and being testable

I'm working on an application which contains an element that needs to make several http calls in a set order, to perform an action successfully. (Interfacing with an external system's API.) We have ...
0
votes
2answers
111 views

How to identify test result as “ignore” (not successful or unsuccessful) in process of execution?

We use Selenium webdriver + SpecFlow for testing our Web application. For some functionality, everything is clear. But imagine the situation: some questions arrive to Web user from external system he ...
2
votes
2answers
311 views

Does it matter how I setup test data when creating unit tests?

I have a unit test similar to the code snippet below, it should check that the AddUser method only allows unique emails. My question is around the Arrange part of this unit test, I use existing ...
1
vote
1answer
2k views

Writing Junit tests for catching exception?

I have a function/method which throws some exception when database is being called. I was writing Junit tests and I was told to have good coverage. So, should I write Junit test which catches ...
2
votes
3answers
136 views

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) { /* ...
1
vote
2answers
203 views

Making public methods virtual to ease testability

I have been looking around for some practices to write testable code and gathered the following: • Public methods virtual if not using interfaces -- makes mocking easier • Dependency injection -- ...
37
votes
7answers
10k views

Is using “new” in the constructor always bad?

I have read that using "new" in a constructor (for any other objects than simple value ones) is bad practice as it makes unit testing impossible (as then those collaborators needs to be created too ...
-2
votes
1answer
97 views

Android testing, what to test? [closed]

I'm quite a noob in the world of testing. I've read all the materials related to Android testing: Unit test Instrumentation test JUnit Robolectric Espresso etc. The thing is that, all the examples ...
5
votes
1answer
383 views

Design Patterns to model complex decision graph

I am currently building a piece of code that creates side-effects based on input parameters. It has around ten input parameters and about six available side-effects. Based on the input parameters, the ...
1
vote
4answers
407 views

Unit test a generic floating point equality function

I've written a function that tests two floating point numbers for approximate equality (see this Code Review question). I'd like to unit test my function, but I'm not positive of the best way to do ...
11
votes
2answers
3k views

Unit Test to test the creation of a Domain Object

I have a Unit Test, which looks like this: [Test] public void Should_create_person() { Assert.DoesNotThrow(() => new Person(Guid.NewGuid(), new DateTime(1972, 01, 01)); } I am asserting that ...
4
votes
4answers
732 views

Should I document a simple Unit Test project?

I have read questions like this: Are unit tests really used as documentation? With regards to code comments; my research so far is telling me: 1) Some developers do not like any code comments and ...
1
vote
2answers
549 views

Should I mock a Domain Service?

I am trying to decide whether to introduce mocks in my isolated Domain Model tests. I have a class method similar to this: public Offer AssignOffer(OfferType offerType, IOfferValueCalculator ...
11
votes
2answers
4k views

Should I include tests in Docker image?

When it comes to tests, I can think of two options: Put both test and application in one image. Include only application code in the image. Create a test-specific container that builds after the ...
0
votes
1answer
79 views

Should I be duplicating Equality methods in the test project?

I have read plenty of questions on here about overriding .equals and .hashcode for testing purposes only. My Domain classes have implemented .equals and .hashcode. Should I be 1) Duplicating these ...
4
votes
1answer
395 views

Should function composition and piping be tested?

Unit testing requires writing tests first then code, on the other hand in F# (and most of the functional languages) some codes are extremely short as follows: let f = getNames >> Observable....
5
votes
3answers
654 views

Should all configurations and platforms run unit tests when application is in development stage?

I have open source C# .NET project at GitHub with Appveyor CI + code coverage. There are configurations like Release and Debug. There's also platforms like x86, x64 and Any CPU. This results to ...
-3
votes
1answer
124 views

Unit-testing function with multiple-dependency [closed]

I am trying to test a function that creates a message exchange graph from IRC chat logs. I am having trouble trying to mock the dependencies. The function makes use of util module. The functions ...
0
votes
1answer
104 views

How to plan unit-test design/structure for Javascript?

In opening I would like to say; I'm pretty new for programing. I'm working with JS for a year. Using Sencha's ExtJS and usign Bryntum's Siesta test tool for unit and integration(ui) tests. Right now ...
2
votes
4answers
212 views

How to write a unit test for a repository method that returns some data, where data can change over time?

I have some code that reads five numbers from a database: class Repository extends DatabaseRepository { function getCoefficients(string $model) { return $this->getDatabaseLink()-&...
0
votes
1answer
112 views

Unit testing certain tasks are done in a process

I have some Scala code that I wish to unit test using ScalaMock: class CancellationManagerSpec extends FlatSpec with MockFactory { "Cancelling a shipment" should "check shipment is not already ...
9
votes
3answers
459 views

Are manually writing unit tests Proof By Example?

We know that writing JUnit tests demonstrates one particular path through you code. One of my associates commented: Manually writing unit tests is Proof By Example. He was coming from the ...
-1
votes
1answer
76 views

How to approach writing a 'test' for a series of input->output sets, that will later be used to verify correctness of a new system?

I have a system ("an engine", which is a piece of code) that takes in several parameters returns some output. The input parameters are several distinct and constrained sets. I can enumerate all of ...
8
votes
4answers
4k views

What is black box unit testing?

I recently had my final exam for a software engineering course for my masters program and one of the questions on the exam was the following: Unit Testing is considered: a. White-box Testing b. Black-...
3
votes
1answer
394 views

Where should an on-team QC perform testing in a feature branching scenario?

I have searched and found a few questions talking about testing in relation to feature branching. My question is a little different. We are a scrum* team of 4 to 5 developers with a dedicated on-...
3
votes
3answers
934 views

Testing a class that uses external interface

I have a class that internally uses an interface that is defined externally. Testing this class becomes difficult since I need to mock out this interface but I am required to reference the external ...
3
votes
2answers
658 views

How to write good javascript unit test descriptions

I come from a python background. I typically write long unit test descriptions that link the test to a user story. The test is as much about justifying why the code exists and how it fits into the ...
1
vote
2answers
160 views

Is there a design pattern that I can use to simplify lots of nested methods

I'm trying to refactor some legacy code that's quite a mess. We're talking a class with 7000 lines and a handfull of methods that are violating the Single Responsibilty Principle so much it hurts to ...
1
vote
1answer
59 views

Mocked dependencies verification - Best practices

I have a simple question about best practices in unit test verifications. Given this example: @Test public void methodUnderTest() { when(mockedDependency.someMethod()).thenReturn(someValue); ...
-1
votes
2answers
373 views

Should I throw ArgumentNullException and should I test it? [duplicate]

Let's take an example of class with 3 dependencies and one method. class Example { private readonly IDependency1 _d1; private readonly IDependency2 _d2; private readonly IDependency3 _d3;...
3
votes
2answers
225 views

Is it sensible to structure unit tests in one class for executing the tests and one for the setup?

When writing unit tests for classes (especially when using DI and mocks) lately I often found it handy to structure my tests to one class actually running the tests and one responsible for the setup, ...
10
votes
5answers
20k views

Unit testing a void method

In order to fix a bug in an application, I modified a method named postLogin by adding a call to an existing method named getShoppingCart. Code protected void postLogin() { getShoppingCart(); } ...
6
votes
1answer
848 views

Does immutability reduce the scope of unit testing?

Recently, I worked on an Android project with Kotlin. As an architecture, there were immutable data classes and functions (not methods which are members of a class), where the functions generate new ...
6
votes
5answers
267 views

How should service method parameters be?

I'm just a junior developer but in about half a dozen projects I worked on there's always this situation: Service methods that take big objects as parameters, but often use just a little portion of ...
2
votes
2answers
248 views

Initialising variable within setUp() method or actual test method when changes are necessary?

I'm starting to wrap my head around PHPunit. My questions is the following. Whenever I use variables that do not change within my range of test methods I can initialize them within my setUp() ...
8
votes
4answers
384 views

What is the value of writing extra unit tests when re-factoring a larger function into smaller functions?

If I have a complex unit tested function: def do_everything(): # turn twizzles # push buttons # move mountain And I re-factor it into some smaller units: def do_everything(): ...
4
votes
4answers
434 views

Should you unit test order of operations? If so, how?

Imagine a psedo-code class like this which does name comparisons: public class NameComparer { public bool DoNamesMatch(Name name1, Name name2) { if(WholeNameMatch(name1, name2)) ...
1
vote
1answer
404 views

Making UnitOfWork testable

I'm in the process of refactoring legacy code. Unfortunately it is a WebForms application with very tight coupling and smelly code. Currently access to database is inside models which looks something ...
2
votes
2answers
238 views

Interrupting software development methodology

I'm in trouble, my team (3 devs including myself) works with mobile and backend development and we are dealing with some problems trying to order this process. Let me try to explain my situation, our ...
1
vote
0answers
43 views

Node JS Tape Unit Testing : All cases inside one function for a method

I am using tape for unit testing in Node JS. I wanted to ask one thing about better coding while writing unit testing. When using different inputs to a single method, is it a better idea to use all ...
84
votes
12answers
13k views

Is it considered 'bad practice' to check file contents/encoding in unit tests?

A bit of context: Earlier today I had to update some SQL code that another colleague of mine provided, and since it’s a pretty large script, it’s stored as a separate file (which is then read and ...
-1
votes
1answer
326 views

Unit Testing: Dependency Inversion

I'm trying to start adding some tests to my code. Please take it easy on me cause i'm still new to this stuffs. As far as i understand dependency inversion, all the dependencies will be place inside ...