Questions tagged [testing]
Software testing is any activity aimed at evaluating an attribute or capability of a program or system and determining that it meets its required results.
testing
50,344
questions
1374
votes
42
answers
584k
views
What's the difference between a mock & stub?
I've read various articles about mocking vs stubbing in testing, including Martin Fowler's Mocks Aren't Stubs, but still don't understand the difference.
959
votes
31
answers
547k
views
Unit Testing C Code [closed]
I worked on an embedded system this summer written in straight C. It was an existing project that the company I work for had taken over. I have become quite accustomed to writing unit tests in Java ...
846
votes
12
answers
607k
views
Gradle build without tests
I want to execute gradle build without executing the unit tests. I tried:
gradle -Dskip.tests build
That doesn't seem to do anything. Is there some other command I could use?
844
votes
8
answers
246k
views
What's the difference between unit, functional, acceptance, and integration tests? [closed]
What is the difference between unit, functional, acceptance, and integration testing (and any other types of tests that I failed to mention)?
819
votes
14
answers
675k
views
How do I properly assert that an exception gets raised in pytest?
Code:
# coding=utf-8
import pytest
def whatever():
return 9/0
def test_whatever():
try:
whatever()
except ZeroDivisionError as exc:
pytest.fail(exc, pytrace=True)
Output:...
807
votes
17
answers
353k
views
What are the differences between unit tests, integration tests, smoke tests, and regression tests? [closed]
What are unit tests, integration tests, smoke tests, and regression tests? What are the differences between them and which tools can I use for each of them?
For example, I use JUnit and NUnit for ...
661
votes
12
answers
552k
views
How to run only one unit test class using Gradle?
I am new to Gradle. I use Gradle 1.10 and Ubuntu 13.
I want to know if there's any command to execute only one unit test class, similar to testOnly in SBT.
608
votes
12
answers
321k
views
How can I write a test which expects an 'Error' to be thrown in Jasmine?
I'm trying to write a test for the Jasmine Test Framework which expects an error. At the moment I'm using a Jasmine Node.js integration from GitHub.
In my Node.js module I have the following code:
...
557
votes
7
answers
264k
views
Writing unit tests in Python: How do I start? [closed]
I completed my first proper project in Python and now my task is to write tests for it.
Since this is the first time I did a project, this is the first time I would be writing tests for it.
The ...
520
votes
14
answers
209k
views
How to unit test abstract classes: extend with stubs?
I was wondering how to unit test abstract classes, and classes that extend abstract classes.
Should I test the abstract class by extending it, stubbing out the abstract methods, and then test all the ...
519
votes
36
answers
539k
views
How to emulate GPS location in the Android Emulator?
I want to get longitude and latitude in Android emulator for testing.
Can any one guide me how to achieve this?
How do I set the location of the emulator to a test position?
480
votes
18
answers
415k
views
How do I run all Python unit tests in a directory?
I have a directory that contains my Python unit tests. Each unit test module is of the form test_*.py. I am attempting to make a file called all_test.py that will, you guessed it, run all files in the ...
467
votes
14
answers
241k
views
What is the difference between unit tests and functional tests?
What is the difference between unit tests and functional tests? Can a unit test also test a function?
412
votes
31
answers
159k
views
Should I test private methods or only public ones? [closed]
I have read this post about how to test private methods. I usually do not test them, because I always thought it's faster to test only public methods that will be called from outside the object. Do ...
396
votes
7
answers
310k
views
Exact time measurement for performance testing [duplicate]
What is the most exact way of seeing how long something, for example a method call, took in code?
The easiest and quickest I would guess is this:
DateTime start = DateTime.Now;
{
// Do some work
...
393
votes
13
answers
349k
views
How do I assert my exception message with JUnit Test annotation?
I have written a few JUnit tests with @Test annotation. If my test method throws a checked exception and if I want to assert the message along with the exception, is there a way to do so with JUnit @...
351
votes
8
answers
256k
views
What is code coverage and how do YOU measure it? [closed]
What is code coverage and how do YOU measure it?
I was asked this question regarding our automating testing code coverage. It seems to be that, outside of automated tools, it is more art than science....
340
votes
19
answers
228k
views
Gradle: How to Display Test Results in the Console in Real Time?
I would like to see test results ( system.out/err, log messages from components being tested ) as they run in the same console I run:
gradle test
And not wait until tests are done to look at the ...
327
votes
17
answers
397k
views
Test process.env with Jest
I have an application that depends on environmental variables like:
const APP_PORT = process.env.APP_PORT || 8080;
And I would like to test that for example:
APP_PORT can be set by a Node.js ...
323
votes
15
answers
271k
views
How do you run a single test/spec file in RSpec?
I want to be able to run a single spec file's tests — for the one file I'm editing, for example. rake spec executes all the specs. My project is not a Rails project, so rake spec:doc doesn't ...
320
votes
6
answers
53k
views
Kotlin and new ActivityTestRule : The @Rule must be public
I'm trying to make UI test for my android app in Kotlin. Since the new system using ActivityTestRule, I can't make it work: it compiles correctly, and at runtime, I get:
java.lang.Exception: The @...
311
votes
7
answers
155k
views
New to unit testing, how to write great tests? [closed]
I'm fairly new to the unit testing world, and I just decided to add test coverage for my existing app this week.
This is a huge task, mostly because of the number of classes to test but also because ...
292
votes
4
answers
138k
views
How to `go test` all tests in my project?
The go test command covers *_test.go files in only one dir.
I want to go test the whole project, which means the test should cover all *_test.go files in the dir ./ and every children tree dir under ...
289
votes
5
answers
614k
views
How to check if a string array contains one string in JavaScript? [duplicate]
I have a string array and one string. I'd like to test this string against the array values and apply a condition the result - if the array contains the string do "A", else do "B".
How can I do that?
280
votes
6
answers
91k
views
Rspec: "array.should == another_array" but without concern for order
I often want to compare arrays and make sure that they contain the same elements, in any order. Is there a concise way to do this in RSpec?
Here are methods that aren't acceptable:
#to_set
For ...
280
votes
9
answers
438k
views
Testing HTML email rendering [closed]
Are there any good tools to easily test how HTML email will look across different email clients? I prefer something with instant feed back rather than a submit and wait service like http://litmusapp....
280
votes
9
answers
280k
views
How do you print in a Go test using the "testing" package?
I'm running a test in Go with a statement to print something (i.e. for debugging of tests) but it's not printing anything.
func TestPrintSomething(t *testing.T) {
fmt.Println("Say hi")
}
When I ...
272
votes
14
answers
326k
views
Stopping an Android app from console
Is it possible to stop an Android app from the console? Something like:
adb stop com.my.app.package
It would speed up our testing process so much. Right now we uninstall/install the app each time to ...
266
votes
20
answers
76k
views
When should I use Debug.Assert()?
I've been a professional software engineer for about a year now, having graduated with a CS degree. I've known about assertions for a while in C++ and C, but had no idea they existed in C# and .NET at ...
265
votes
5
answers
218k
views
toBe(true) vs toBeTruthy() vs toBeTrue()
What is the difference between expect(something).toBe(true), expect(something).toBeTruthy() and expect(something).toBeTrue()?
Note that toBeTrue() is a custom matcher introduced in jasmine-matchers ...
264
votes
19
answers
226k
views
Making the Android emulator run faster
The Android emulator is a bit sluggish. For some devices, like the Motorola Droid and the Nexus One, the app runs faster in the actual device than the emulator. This is a problem when testing games ...
259
votes
11
answers
344k
views
How to configure "Shorten command line" method for whole project in IntelliJ
When I run tests I get the error "Command line is too long".
It works if I set the "Shorten command line" method in the Run/Debug configuration to "JAR manifest" for the specific method or class, but ...
258
votes
22
answers
201k
views
Trying to mock datetime.date.today(), but not working
Can anyone tell me why this isn't working?
>>> import mock
>>> @mock.patch('datetime.date.today')
... def today(cls):
... return date(2010, 1, 1)
...
>>> from datetime ...
252
votes
5
answers
202k
views
Force retesting or disable test caching
Problem:
When I run the same go test twice the second run is not done at all. The results are the cached ones from the first run.
PASS
ok tester/apitests (cached)
Links
I already ...
252
votes
15
answers
102k
views
Determine if a function exists in bash
Currently I'm doing some unit tests which are executed from bash. Unit tests are initialized, executed and cleaned up in a bash script. This script usualy contains an init(), execute() and cleanup() ...
247
votes
9
answers
358k
views
How can I time a code segment for testing performance with Pythons timeit?
I've a python script which works just as it should, but I need to write the execution time. I've googled that I should use timeit but I can't seem to get it to work.
My Python script looks like this:
...
246
votes
10
answers
225k
views
How do I disable a test using pytest?
Let's say I have a bunch of tests:
def test_func_one():
...
def test_func_two():
...
def test_func_three():
...
Is there a decorator or something similar that I could add to the ...
238
votes
1
answer
337k
views
Verify a method call using Moq
I am fairly new to unit testing in C# and learning to use Moq. Below is the class that I am trying to test.
class MyClass
{
SomeClass someClass;
public MyClass(SomeClass someClass)
{
...
230
votes
23
answers
354k
views
How to check whether dynamically attached event listener exists or not?
Here is my problem: is it somehow possible to check for the existence of a dynamically attached event listener? Or how can I check the status of the "onclick" (?) property in the DOM? I have ...
226
votes
15
answers
240k
views
Best way to compare 2 XML documents in Java
I'm trying to write an automated test of an application that basically translates a custom message format into an XML message and sends it out the other end. I've got a good set of input/output ...
223
votes
20
answers
186k
views
How do I simulate a low bandwidth, high latency environment? [closed]
I need to simulate a low bandwidth, high latency connection to a server in order to emulate the conditions of a VPN at a remote site. The bandwidth and latency should be tweakable so I can discover ...
219
votes
21
answers
323k
views
How to test code dependent on environment variables using JUnit?
I have a piece of Java code which uses an environment variable and the behaviour of the code depends on the value of this variable. I would like to test this code with different values of the ...
215
votes
9
answers
269k
views
ReferenceError: describe is not defined NodeJs
I am trying to define some endpoints and do a test using nodejs. In server.js I have:
var express = require('express');
var func1 = require('./func1.js');
var port = 8080;
var server = express();
...
214
votes
16
answers
269k
views
How to measure test coverage in Go
Has anyone succeeded in generating code coverage for Go unit tests? I can't find a tool for that on the web.
208
votes
10
answers
304k
views
How do I get my Maven Integration tests to run
I have a maven2 multi-module project and in each of my child modules I have JUnit tests that are named Test.java and Integration.java for unit tests and integration tests respectively. When I execute:...
203
votes
5
answers
171k
views
ScalaTest in sbt: is there a way to run a single test without tags?
I know that a single test can be ran by running, in sbt,
testOnly *class -- -n Tag
Is there a way of telling sbt/scalatest to run a single test without tags? For example:
testOnly *class -- -X 2
...
203
votes
5
answers
72k
views
Sharing Test code in Maven
How can you depend on test code from another module in Maven?
Example, I have 2 modules:
Base
Main
I would like a test case in Main to extend a base test class in Base. Is this possible?
Update:...
202
votes
6
answers
159k
views
Skip one test in test file Jest
I'm using Jest framework and have a test suite. I want to turn off/skip one of my tests.
Googling documentation doesn't give me answers.
Do you know the answer or source of information to check?
201
votes
31
answers
87k
views
Disadvantages of Test Driven Development? [closed]
What do I lose by adopting test driven design?
List only negatives; do not list benefits written in a negative form.
196
votes
5
answers
168k
views
What is the difference between mocking and spying when using Mockito?
What would be a use case for a use of a Mockito spy?
It seems to me that every spy use case can be handled with a mock, using callRealMethod.
One difference I can see is if you want most method ...