Questions tagged [testing]
55657 questions
14
votes
13
answer
10.6k
Views
Visual Studio Debugger skips over breakpoints
My Visual Studio 2008 IDE is behaving in a very bizarre fashion while debugging a unit test: I have a breakpoint and when I hit it and then try to step with F10 the test concludes. If I Set breakpoints on every line inside the method being tested I will end up at a random one, not the next one on th...
19
votes
5
answer
10.6k
Views
Integration Testing best practices
Our team has hundreds of integration tests that hit a database and verify results. I've got two base classes for all the integration tests, one for retrieve-only tests and one for create/update/delete tests. The retrieve-only base class regenerates the database during the TestFixtureSetup so it only...
2
votes
1
answer
10.5k
Views
Ruby TypeError: no implicit conversion of String into Array
I have a test that returns TypeError: no impliciit conversion of String into Array, when it hits a certain section of my code. If I run the code outside of rspec it runs just fine, so I'm not sure why this is happening.
require 'spec_helper'
require 'digital_ocean_size_list'
describe Chef::Knife::Di...
28
votes
3
answer
10.5k
Views
Stub a Method That Returns a BOOL with OCMock
I'm using OCMock 1.70 and am having a problem mocking a simple method that returns a BOOL value. Here's my code:
@interface MyClass : NSObject
- (void)methodWithArg:(id)arg;
- (BOOL)methodWithBOOLResult;
@end
@implementation MyClass
- (void)methodWithArg:(id)arg {
NSLog(@'methodWithArg: %@', arg);
}...
16
votes
2
answer
10.5k
Views
Test a function that contains a setTimeout()
I have a close function in my component that contains a setTimeout() in order to give time for the animation to complete.
public close() {
this.animate = 'inactive'
setTimeout(() => {
this.show = false
}, 250)
}
this.show is bound to an ngIf.
this.animate is bound to an animation.
I have a test that...
20
votes
4
answer
10.5k
Views
What is the easiest way to mock an IMAP or POP server for unit tests? [duplicate]
This question already has an answer here:
Working with a Java Mail Server for Testing
5 answers
I want to unit test a Java application that fetches mails from an email inbox, much like this guy. Currently, I run the unit tests against a real mailbox on our company's real mailserver which was easy t...
18
votes
5
answer
10.5k
Views
Should we unit test logging?
It's usual to see logging functionality in the code:
public class A {
private static final Log LOG = LogFactory.getLog(A.class);
and usage:
} catch (Exception e) {
LOG.error(e.getMessage(), e);
throw e;
}
but I never saw even single unit test for such code.
Off course I do test throwing exception a...
11
votes
3
answer
10.5k
Views
How can you use “external” configuration files (i.e. with configSource) with an MSTest unit test project?
For simplicity, I generally split a lot of my configuration (i.e. the contents of app.config and web.config) out into separate .config files, and then reference them from the main config file using the 'configSource' attribute. For example:
and then placing all of the key/value pairs in that appSett...
7
votes
5
answer
10.5k
Views
uncaughtException after a Protractor run
After upgrading to Protractor 4.0.0 and adjusting the config because of the breaking changes, we finally have our tests launching.
Now, the problem is that after a test run it fails with:
[09:52:22] E/launcher - 'process.on('uncaughtException'' error, see launcher
[09:52:22] E/launcher - Process exi...
12
votes
1
answer
10.5k
Views
in angular js while testing the controller got Unknown provider
I have the following controller:
angular.module('samples.controllers',[])
.controller('MainCtrl', ['$scope', 'Samples', function($scope, Samples){
//Controller code
}
Which dependent on the following service:
angular.module('samples.services', []).
factory('Samples', function($http){
// Service code...
2
votes
4
answer
10.5k
Views
How to mock a For Loop using Mockito
I'm a newbie to mockito. My question is how can I mock a for loop using Mockito?
For Eg: This is the main Class:
import java.util.HashSet;
import java.util.Set;
public class stringConcatination {
public static void main(String[] args) {
Set stringSet = new HashSet();
stringSet.add('Robert');
strin...
4
votes
2
answer
10.5k
Views
Mocking assert_called_with in Python
I'm having some trouble understanding why the following code does not pass:
test.py
import mock
import unittest
from foo import Foo
class TestFoo(unittest.TestCase):
@mock.patch('foo.Bar')
def test_foo_add(self, Bar):
foo = Foo()
foo.add(2, 2)
Bar.add.assert_called_with(2, 2)
if __name__ == '__main_...
8
votes
3
answer
10.5k
Views
PhantomJS and Selenium Webdriver - How to clear session
I'm using Selenium Webdriver (Java) and PhantomJS to test a complex JS driven website. My problem is, that the PhantomJS browser keeps the session between two tests which leads to errors in the test setup.
If I run the tests with Firefox everything works fine because Firefox uses a clean session for...
6
votes
3
answer
10.5k
Views
Unit test: assert not work?
I'm applying UnitTest just for a while, and today I met something very strange. Considering the following code:
TestObject alo = null;
assert alo != null; // Pass!!!
Assert.assertNotNull(alo); // Fail, as expected.
I googled around and find that assert is java-built-in, while assertNotNull is JUnit...
1
votes
3
answer
10.5k
Views
How to check bluetooth connection state with paired device in Android
I develop an bluetooth app which will connect to a paired device and send a message, but I have to test connection before. I've tried many options, but nothing works in good way. So could you send me any example of code which can do it? I made an thread, but I can't get an good state of connection t...
17
votes
3
answer
10.5k
Views
Using google mock for C code
I'm maintaining a legacy project written in C and it's unfeasible to get it running with a C++ compiler. Since the code is cross compiled it is however possible to run unit-tests or similar in a host environment. hence it's also possible to interface with a C++ host compiler and use google-test and...
3
votes
3
answer
10.5k
Views
How do I Unit Test HTTPServlet?
I want to test my servlet with http://www.easymock.org/
How do I write the Unit Testing Code?
I update my code with your responce.
I just used Google and made this code now.
Here is my Servlet:
package com.i4ware.plugin.timesheet;
import java.io.IOException;
import com.atlassian.jira.issue.Issue;
im...
20
votes
1
answer
10.5k
Views
Python unitest - Use variables defined in module and class level setup functions, in tests
Python unittest using nosetests to experiment with Python Class and Module fixtures, to have minimal setup across my tests.
The problem I am facing is, I am not sure how to use any variables defined in the setupUpModule and the setUpClass functions in my tests (example :- test_1).
This is what I am...
4
votes
2
answer
10.5k
Views
How can I simulate blur when testing directives in angularjs?
The problem
I am trying to test some directives (code for both below). One of them is an 'email' (called 'epost' in the code(norwegian)) directive. The solution to this should work for all of them, so I am keeping it to this one for now.
Technologies: Angularjs, Jasmine, Requirejs, (grunt & karma ru...
6
votes
3
answer
10.5k
Views
Make protractor test occupy the entire screen
I have seen a couple questions online related to this issue (How to set default browser window size in Protractor/WebdriverJS) but they don't address my issue.
I have the tests that I want to be able to run successfully on a laptop screen or desktop screen of ant size. I had tried all of these metho...
6
votes
4
answer
10.5k
Views
Mocking a call on a public method of an abstract class without subclassing the abstract Class, using mockito prefererably
I am writing an unit testing using JUNIT + Mockito to test a method like :
public someObject methodUnderTest(){
SomeObject obj = SomeAbstractClass.someMethod();
if(obj!=null){
obj.someOtherMethod();
}
return someThing;
}
And I would like to mock the call on abstract Class 'SomeAbstractClass' mention...
21
votes
1
answer
10.5k
Views
Where is Create Unit Test in VS 2017?
I understand that this question has been asked before on SO and it appears that this feature was removed from VS at some point. But I am looking at a Microsoft tutorial right now and that says there should be a Create Unit Test function in VS 2017.
I'm trying to test ASP.NET Core MVC controllers. I...
8
votes
2
answer
10.5k
Views
How write stub method with NUnit in C#
I have 2 classes:
FirstDeep.cs
SecondDeep.cs
I did simple code for example:
class FirstDeep
{
public FirstDeep() { }
public string AddA(string str)
{
SecondDeep sd = new SecondDeep();
bool flag = sd.SomethingToDo(str);
if (flag == true)
str = string.Concat(str, 'AAA');
else
str = string.Concat(str,...
14
votes
1
answer
10.5k
Views
How to fix NoSuchMethodError?
I use Scala 2.10.0RC1 and sbt 0.12.1.
What causes and how can I fix this runtime error (runs fine on 2.9.2)?
The exact error message is:
java.lang.NoSuchMethodError: scala.Predef$ArrowAssoc$.extension$$minus$greater(Ljava/lang/Object;Ljava/lang/Object;)Lscala/Tuple2;
14
votes
7
answer
10.5k
Views
Unit testing destructors?
Is there any good way to unit test destructors? Like say I have a class like this (contrived) example:
class X
{
private:
int *x;
public:
X()
{
x = new int;
}
~X()
{
delete x;
}
int *getX() {return x;}
const int *getX() const {return x;}
};
Is there any good way to unit test this to make sure x get...
15
votes
5
answer
10.5k
Views
Xcode UI Testing - typing text with typeText() method and autocorrection
I've got a test like below:
let navnTextField = app.textFields['First Name']
let name = 'Henrik'
navnTextField.tap()
navnTextField.typeText('Henrik')
XCTAssertEqual(navnTextField.value as? String, name)
Problem is that by default my iPhone Simulator has got Polish keyboard because of the system set...
4
votes
8
answer
10.5k
Views
What tools are available for QA a Website? That is treated as a Unit Testing
We are looking for QA tool that allow us to test functionality in our web applications. At this moment we QA all our work/enhancements/defects by hand, but we have so many webapps that is difficult to QA the entire site for a few changes.
We want to have a list of Test Cases that we will run every...
5
votes
3
answer
10.5k
Views
How to extract multiple values with a regular expression in Jmeter
I am running tests with jmeter and I need to extract with a Regular Expression:
insertar?sIws2kyXGJJA_01==
insertar?sIws2kyXGJJA_02==
in the following String:
[\'EMBPAGE1_00010001\',\'**insertar?sIws2kyXGJJA_01==**\',1,100,\'%\',300,\'px\',0,\'center\',\'\',\'[\'EMBPAGE1_00010002\',\'**insertar?sIw...
5
votes
1
answer
10.5k
Views
Mock an enum using Mockito in Java
How can I mock an enum for testing purposes using Mockito? Given this sample for the enum:
public enum TestEnum {
YES,
NO
}
and this one for the method using the enum:
public static boolean WorkTheEnum(TestEnum theEnum) {
switch (theEnum) {
case YES:
return true;
case NO:
return false;
default:
// t...
18
votes
2
answer
10.5k
Views
How to order methods of execution using Visual Studio to do integration testing?
I have 2 questions in regard doing integration testing using VS 2010
First, I'm really in need of finding a way to execute these testing methods in the order I want them to. Note: I know in Unit Testing, methods should run standalone from anything else, but these are integration tests which I do de...
13
votes
4
answer
10.5k
Views
JUnit @BeforeClass non-static work around for Spring Boot application
JUnit's @BeforeClass annotation must be declared static if you want it to run once before all the @Test methods. However, this cannot be used with dependency injection.
I want to clean up a database that I @Autowire with Spring Boot, once before I run my JUnit tests. I cannot @Autowire static fields...
33
votes
1
answer
10.5k
Views
JUnit4 - AssertionFailedError: No tests found
I'm using AndroidJUnitRunner with Espresso.
I wrote a simple test but always receive this exception. According to Stackoverflow answers, the problem is messing up the JUnit3 and JUnit4 but I have never used JUnit3 in my project.
junit.framework.AssertionFailedError: No tests found in com.walletsaver...
21
votes
4
answer
10.5k
Views
How can I mock JodaTime actual date?
I want to test this method:
public FirmOrder findActiveByModelColor(ModelColor modelColor) {
Query query = em.createQuery('FROM FirmOrder fo WHERE fo.modelColor = :modelColor AND fo.year = :year AND fo.month = :month');
query.setParameter('modelColor', modelColor);
query.setParameter('year', new Dat...
1
votes
2
answer
10.5k
Views
Laravel 5: Model->fill() ignores $fillable property in unit tests
I have a user controller with the following validation rules:
public function store(Request $request)
{
...
$this->validate($request, [
'name' => 'required',
'email' => 'email|required|unique:users',
'password' => 'confirmed|max:32|min:8|required',
'roles' => 'exists:roles,id|required',
]);
$user =...
22
votes
2
answer
10.5k
Views
Surefire doesn't launch test in src/main/java
I needed to move some src/test/java to src/main/java according to this recommandation from maven-jar-plugin documentation => http://maven.apache.org/plugins/maven-jar-plugin/usage.html
I did so because, i used tests (helper) classes in another projects in test scope.
So i create my-project-test, mov...
6
votes
1
answer
10.4k
Views
Using separate persistence.xml files for production and test with Spring 3.1
OK, sorry, I looked for answers to this for hours, but it took me entering the whole question for StackOverflow to bubble up the link I was looking for. You can read a lot of relevant information here.
I have a Spring project created with Spring Roo to use Hibernate and MySQL. However, for testing...
13
votes
2
answer
10.4k
Views
Running each JUnit test in a separate JVM in Eclipse?
I have a project with nearly 500 individual tests in around 200 test classes. Some of these tests don't do a great job of tearing down their own state after they're finished, and in Eclipse this results in some tests failing. The tests all pass when running the test suite from the command line via A...
25
votes
2
answer
10.4k
Views
eclemma branch coverage for switch: 7 of 19 missed
I have this switch system and I'm using eclemma to test the branch coverage. We are required to have at least 80% in branch coverage for everything so I'm trying to test as much as possible.
However, eclemma tells me this switch system is not fully tested in terms of branch coverage.
pos = p.getCurr...
13
votes
4
answer
10.4k
Views
Unit test code with Java 8 Lambdas
I have been using Java 8 for some months, and I have started to use Lambda expressions, which are very convenient for some cases. However, I often come across some problems to unit test the code that uses a Lambda.
Take as an example the following pseudo-code:
private Bar bar;
public void method(int...
15
votes
1
answer
10.4k
Views
How do I run xctest from the command-line with Xcode 5?
I found a command-line tool called 'xctest' that apparently can run the unit tests in your project. This executable lives here:
/Applications/Xcode.app/Contents/Developer/usr/bin/xctest
When I try to run this executable on my xctest bundle, I'm using:
$ ./xctest /Users/myusername/Library/Developer...
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
- 88
- 89
- 90
- 91
- 92
- 93
- 94
- 95
- 96
- 97
- 98
- 99
- 100
- 101
- 102
- 103
- 104
- 105
- 106
- 107
- 108
- 109
- 110
- 111
- 112
- 113
- 114
- 115
- 116
- 117
- 118
- 119
- 120
- 121
- 122
- 123
- 124
- 125
- 126
- 127
- 128
- 129
- 130
- 131
- 132
- 133
- 134
- 135
- 136
- 137
- 138
- 139
- 140
- 141
- 142
- 143
- 144
- 145
- 146
- 147
- 148
- 149
- 150
- 151
- 152
- 153
- 154
- 155
- 156
- 157
- 158
- 159
- 160
- 161
- 162
- 163
- 164
- 165
- 166
- 167
- 168
- 169
- 170
- 171
- 172
- 173
- 174
- 175
- 176
- 177
- 178
- 179
- 180
- 181
- 182
- 183
- 184
- 185
- 186
- 187
- 188
- 189
- 190
- 191
- 192
- 193
- 194
- 195
- 196
- 197
- 198
- 199
- 200
- 201
- 202
- 203
- 204
- 205
- 206
- 207
- 208
- 209
- 210
- 211
- 212
- 213
- 214
- 215
- 216
- 217
- 218
- 219
- 220
- 221
- 222
- 223
- 224
- 225
- 226
- 227
- 228
- 229
- 230
- 231
- 232
- 233
- 234
- 235
- 236
- 237
- 238
- 239
- 240
- 241
- 242
- 243
- 244
- 245
- 246
- 247
- 248
- 249
- 250