Questions tagged [testing]

55657 questions
8

votes
3

answer
4.3k

Views

Eclipse Maven Build and Test with One Button

The most common build activity I do in Eclipse (other than allowing auto-build to do its thing) is to perform a 'Maven Build...' with parameters of clean and package. This runs all my tests. m2eclipse does a great job with this, and I like the output. If a test breaks, I then jump to using the JU...
Marvo
2

votes
1

answer
4.3k

Views

How to mock WS client and provide response in camel route

I want to mock WS client call in camel route, check request and provide response. Here is a test package com.example.helloworld; import org.apache.camel.*; import org.apache.camel.component.mock.MockEndpoint; import org.apache.camel.test.junit4.CamelSpringTestSupport; import org.junit.Test; import o...
deveproject
1

votes
1

answer
4.3k

Views

Using PHPUnit with Selenium, how can I test that an element contains exactly something?

I'm using PHPUnit and Selenium, and currently using something like $this->assertElementContainsText('id=foo', 'bar') which passes when it finds this: bar However, I am also trying to test for a case where p#foo might contain other HTML, and I want to test that the contents matches exactly. In my min...
shanebonham
3

votes
2

answer
4.3k

Views

How to patch Python class using Mock library

I'm having trouble patching a class for my testing. I'm trying to patch something that belongs to Scrapy - a HtmlXpathSelector class. Here is some code: from scrapy.selector import HtmlXPathSelector from mock import MagicMock, patch with patch('scrapy.selector.HtmlXPathSelector') as MockHtml: instan...
Edwardr
5

votes
2

answer
4.3k

Views

Automatic failing/non-execution of interdependent tests in Robot Framework

If say I've a 100 test cases to run in which test case no 24, 38 and 99 are interdependent. Then is it possible that while the 99th test case is getting executed you find out the status of a previously executed test case (say the 24th or 38th test case)? In my case, the 99th test case depends on the...
2

votes
2

answer
4.3k

Views

Mock Verify/VerifyAll before or after Assertion

I have been used to following code pattern while writing my test public void TestMethod_Condition_Output() { //Arrange---------------- Mock temp = new Mock(); temp.setup....... //Act-------------------- classinstance.TestMethod() //Assert------------------ temp.VerifyAll(); Assert.AreNotEqual(.....)...
DotNetInfo
4

votes
1

answer
4.3k

Views

OpenGl alpha test - How to replace AlphaFunc deprecated?

I'm trying to draw sphere with alpha, but I have a problem with my Z-buffer. Some pixels are transparent but write in the Zbuffer so a pixel opaque just behind is hidden. Here are my settings: gl Enable: gl DEPTH_TEST. gl DepthFunc: gl LEQUAL. gl Disable: gl CULL_FACE. gl Enable: gl BLEND. gl Blen...
user3755394
15

votes
3

answer
4.3k

Views

Best practices for Android Unit Testing?

I am developing a mobile android app. What are the most common libraries/frameworks used for Android unit testing? I feel that most of the business logic, database testing, Web services testing can all be done using JUnit. However, what's the best approach for testing UI, the UI workflow, etc? For e...
codeshark
1

votes
1

answer
4.3k

Views

Mocking a static final method using PowerMock

I have class with all the methods static and final. How do I mock a method which is both static and final in the class. public class UtilityClass{ public static final void utilityMethod(){ } public static final Integer anotherUtilMethod(){ } } How to mock utilMethod() and anotherUtilMethod() using P...
Ganesh P
1

votes
1

answer
4.3k

Views

iphone device Testing errors?

I'm currently trying to test my iPhone application on a real device but I have multiple errors like that: Undefined symbols: '_OBJC_CLASS_$_UITableView', referenced from: [email protected] in CustomSearchController.o [email protected] in HistoryController.o [email protected] in...
Mathieu
1

votes
1

answer
4.3k

Views

Running NUnit tests multiple times

I have a suite of NUnit tests, some of which fail intermittently, probably because of timing problems. I'd like to find these flaky unit tests. Is there a way to repeat each test multiple times without having to put a Repeat() attribute on each test? We routinely use the resharper and ncrunch runner...
Phillip Ngan
6

votes
2

answer
4.3k

Views

Cannot get @Rollback to work for my Spring JPA Integration Test

This here is a little test class that I have. Problem is that it is not rolling back the transaction after each test run. What have I done wrong? :) @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = { '/META-INF/catalog-spring.xml' }) @TransactionConfiguration(transactionMana...
willcodejavaforfood
3

votes
3

answer
4.3k

Views

UI automation in windows phone 8 application

i have searched for automating UI in windows phone 8 applications and i did not get any useful tool or framework for that so is there any framework to automate UI application in windows phone 8?
1

votes
2

answer
4.3k

Views

Angular 2 unit testing “Cannot read property 'unsubscribe' of undefined”

I have sample TestComp with ngOnInit and ngOnDestroy methods and ActivatedRoute subscription. @Component({ selector: 'test', template: '', }) export class TestComp implements OnInit, OnDestroy { constructor ( private route: ActivatedRoute ) { } ngOnInit() { this.subscription = this.route.data .subsc...
styopdev
17

votes
1

answer
4.3k

Views

difference between django.test.TestCase vs unittest vs django.utils.unittest.TestCase

I am still using Django 1.2.1, and I think with the newer Django we don't import unittest and then do unittest.TestCase. Illustration import unittest class TestThis(unittest.TestCase): from django.utils.unittest import TestCase class TestThis(TestCase): from django.test import TestCase class TestThi...
CppLearner
13

votes
3

answer
4.3k

Views

How do I fake-time a jQuery animation using Sinon in a Jasmine unit test?

I have a 1 second jQuery .animate action that launches 5 seconds after page load. I set up a Sinon timer in my Jasmine unit testing code and test after a tick of 7 seconds to see if the post-animation properties are as they should be. It doesn't work right, so I've placed an instance of the animatio...
gcdev
1

votes
2

answer
4.3k

Views

how to easily create a unit test to an existing method in VS2012

as posted here: http://connect.microsoft.com/VisualStudio/feedback/details/748493/missing-funtionality-of-creating-a-new-unit-test-from-editor there is no automatic way to add UT to existing code Posted by doronneu on 6/14/2012 at 4:53 AM So How do I add new tests to an existing testing project with...
Elad Benda
3

votes
6

answer
4.3k

Views

How to unit test and mock a method that takes a file as a parameter

I have a class CollectionObject which creates a ArrayList. public class CollectionObject { private List collectionObject; public CollectionObject() { collectionObject = new ArrayList(); } public List getCollectionObject() { return collectionObject; } public void add(final String stringToWrite) throw...
shawn derik
2

votes
1

answer
4.3k

Views

Jmeter multiple executions for each record from CSV

I have a CSV of 100 records/rows, that I wish to execute (through a service) using JMeter. Now, I want to execute each record 3 times (each after a delay of say, 5 secs), and do the same for all 100 records in the CSV. How can I do so using JMeter?
Saket
4

votes
2

answer
4.3k

Views

How to do mock a function using gomock in Go?

I am new to Go and doing small simple project + doing testing habit to learn.. but I am having trouble in setting up test using mock. Specifically in setting up the mock object sample/sample.go package sample import ( 'fmt' 'net/http' ) func GetResponse(path, employeeID string) string { url := fmt.S...
saruberoz
3

votes
3

answer
4.3k

Views

How can you cleanup a Python UnitTest when setUpClass fails?

Say I have the following Python UnitTest: import unittest def Test(unittest.TestCase): @classmethod def setUpClass(cls): # Get some resources ... if error_occurred: assert(False) @classmethod def tearDownClass(cls): # release resources ... If the setUpClass call fails, the tearDownClass is not calle...
sickgemini
20

votes
3

answer
4.3k

Views

How can I use Google Test with my project that builds via autotools?

It seems like there are a few answers that kind-of, sort-of make sense, but that I don't know how to carry out. And I haven't found a comprehensive answer. The First Problem Google Test should not be an installed library, it should be built with the project. (See the FAQ.) As far as I can tell, this...
Joel
2

votes
2

answer
4.3k

Views

Test @Webservice EJBs with WebServiceContext (using OpenEJB?)

I have some EJBs as JAX-WS Web Service: @WebService @Stateless @Remote(MobileFacade.class) public class MobileFacadeBean implements MobileFacade { ... @Resource WebServiceContext wsc; ... } Within this Web Service class, a WebServiceContext is injected via @Resource. I use this WebServiceContext to...
Frank
1

votes
2

answer
4.3k

Views

angular 2 testing - Can't create a component

My app has lots of modules with many components and services and other Angular2 stuff. Now I'm trying to use TestBed approach to create a unit tests with jasmine + karma. I've faced an error during revealing proof of concept. I've created a test for one of my components, which looks like this: let m...
a.kozlenkov
8

votes
1

answer
4.3k

Views

RunWith and ContextConfiguration weird behaviour

I have this very simple class : @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations={'classpath*:/application-context-this-does-not-exist.xml'}) public class HTMLSourceExtractorImplTest { @Autowired ApplicationContext context; @Test public void test(){ String [] beans = context.g...
Eugene
7

votes
2

answer
4.3k

Views

How to perform unittest for floating point outputs? - python

Let's say I am writing a unit test for a function that returns a floating point number, I can do it as such in full precision as per my machine: >>> import unittest >>> def div(x,y): return x/float(y) ... >>> >>> class Testdiv(unittest.TestCase): ... def testdiv(self): ... assert di...
alvas
7

votes
2

answer
4.3k

Views

Unit Test Web Api 2 Mock User

I'm trying to mock the User.Identity in my Api Controller test. This is my api method: [Route(Urls.CustInfo.GetCustomerManagers)] public HttpResponseMessage GetCustomerManagers([FromUri]int groupId = -1) { var user = User.Identity.Name; if (IsStaff(user) && groupId == -1) { return ErrorMissingQueryS...
ozstudent
7

votes
2

answer
4.3k

Views

Get Code Coverage Statistics IOS

I am trying to get the code coverage statistics from the .gcda file. I know similar questions are there but I did not get what I want then. Till now, I got the .gcda files after some googling on how to do it. Got Coverstory to read them. Now when I open one .gcda file it will give me the code covera...
Prajwal
3

votes
1

answer
4.3k

Views

Unit testing in AngularJS with mock $resource

Trying to get some units tests in AngularJS (using jasmine & karma) working and struggling to comprehend dependency injection... current error message in karma reads 'Error: Argument 'fn' is not a function, got string' app.js angular.module('App', [ 'App.Services', 'App.Controllers', 'App.Directive...
Rob B
11

votes
2

answer
4.3k

Views

Mocking Delegate.Invoke() using Moq throws InvalidCast exception in LINQ

Let's say that I have IService interface: public interface IService { string Name { get; set; } } And a delegate Func that returns this interface. In my unit test I want to mock the delegate's Invoke() method using Moq like this: [TestMethod] public void UnitTest() { var mockService = new Mock(); va...
Nikolai Samteladze
5

votes
2

answer
4.3k

Views

unit-testing abstract classes and protected methods inside them

how can I test abstract classes and protected methods inside them? I know some of you will suggest that I shouldn't test the abstract class, but rather test the classes that derive from it instead. Thing is, I don't want to do that. I want to strictly test the abstract class itself. Here is the samp...
Anthony
12

votes
5

answer
4.3k

Views

Play! framework: customize which tests are run

I have a Play! 2 for Scala application, and I am using Specs2 for tests. I can run all tests with the test command, or a particular specification with test-only MyParticularSpec. What I would like to do is mark some particular specifications, or even single methods inside a specification, in order t...
Andrea
1

votes
1

answer
4.3k

Views

EasyMock: Partially mocked class

Do all the methods that are not mocked on a mocked class work work as normal? E.G. Given the object public class Shape { public void createShape(...){ .... } public void removeShape(...){ .... } ... } if this was mocked out like shape = createMock(Shape.class, new Method[]{Shape.class.getMethod('re...
flexinIT
4

votes
1

answer
4.3k

Views

Jest/React - How to use global object in unit tests?

I use CommonJS modules with require() except React, which is global: // I don't want require React in every module: // var React = require('react'); var MyComponent = React.createClass({ // React is global here }); When running a unit test on MyComponent, Jest can't find React. Is there a way to tel...
Csati
7

votes
3

answer
4.3k

Views

Testing in Hamcrest that exists only one item in a list with a specific property

With Hamcrest we can easily test that exists at least one item in a list with a specific property, e.g. List myList = .... MatcherAssert.assertThat(myList, Matchers.hasItem(Matchers.hasProperty('fieldName', Matchers.equalTo('A funny string'))))); where the class Pojo is something like: public class...
JeanValjean
1

votes
2

answer
4.3k

Views

testing url connection java html

When I am testing the list of url's to see if the connection is 'alive' or 'dead', I run into this site: (www.abbapregnancy.org) then site is blank with no information. How can I make an if statement to test for sites like this? Feel free to comment or suggest ideas. My code is currently like this:...
Next_Line_Nick
6

votes
2

answer
4.3k

Views

How to validate a unit test with random values

How to validate a unit test with random values? I need guarantee that gen_age returns an integer between 15 and 99, but this code is not correct. import random import unittest def gen_age(): # generate integer between 15 and 99 return random.randint(15, 99) class AgeTest(unittest.TestCase): def setU...
Regis da Silva
2

votes
4

answer
4.3k

Views

VS2010's Test List Editor functionality in VS2012 (Update)

Is it possible to get the same Test List Editor functionality from Visual Studio 2010 in Visual Studio 2012? What I would like to do is make a set of lists containing the tests I want to run. When running a list, I want to be able to move tests easily from one list to another. This was easy in VS201...
TimothyHeyden
12

votes
4

answer
4.3k

Views

Delphi unit test for a TThread with FreeOnTerminate = True

What is the best way to write a Delphi DUnit test for a TThread descendant when FreeOnTerminate = True? The TThread descendant returns a reference which I need to test for, but I can't figure out how to wait for the thread to finish in the test... unit uThreadTests; interface uses Classes, TestFrame...
Rick Wheeler
6

votes
5

answer
4.3k

Views

Python unittest TestCase with inheritance

Currently I have many similar unittest TestCases. Each TestCase contains both data (input values + expected output values) and logic (call the SUT and compare the actual output with the expected output). I would like to separate the data from the logic. Thus I want a base class that only contains th...
compie