Questions tagged [unit-testing]

26400 questions
1

votes
4

answer
1.7k

Views

Testing a method that returns an Object with Mockito

I would like to test makeBooks() method that returns a book object with Mockito. So the test will check whether it returns a book object or not. How do I do that? Below is my factory that produces books. Below that class is my Mockito test class. I got an error code saying "I misused the Mockito" I...
Wai Hein
1

votes
1

answer
3.3k

Views

Error when running unit tests in automated build since VS upgrade to 2013 on TFS2012

I started creating automated builds in TFS 2012 using a build server with VS2012 on it. Everything was running fine, but then we updated the build server to VS2013(still with TFS 2012). Now no units execute. I get the error: Handle Test Run Exception Could not load file or assembly 'Microsoft.Visual...
user3115698
1

votes
1

answer
3.1k

Views

Run phpunit tests on symfony2 core and bundles

I created a new symfony 2.4 project and would like to run the test suite on core and bundles just to know phpunit is installed properly and to see the outputs, but can't figure out what am I doing wrong I installed phpunit via composer Now there is a link to phpunit bin/phpunit I try bin/phpunit -c...
jeff
1

votes
1

answer
242

Views

Automation testing framework for webservices [closed]

I am new to VS( about 6 months), we have an application built using WCF and I am looking for some pointer to build a automation framework around it. I tried with soap UI but its too simple for my application, any suggestions/pointers where and how should I start building this framework( only option...
user3285525
1

votes
1

answer
1k

Views

Simulate an ECONNRESET error on a Node.js net.Socket instance

I'm writing some unit tests and I'd like to simulate a connection loss (ECONNRESET) on a net.Socket instance as part of one of the tests. What would be the best way to go about doing this? Thanks
9point6
1

votes
1

answer
1.9k

Views

python mocking third party modules

im trying to test some classes that process tweets. Im using sixohsix twitter to deal with Twitter API. I have a class that acts as a facade for the Twitter classes, and my idea was to mock the actual sixohsix classes to simulate the arrival of tweets, by randomly generate new tweets or retrieving...
Sebastian
0

votes
0

answer
36

Views

How do I unit test a feature that prints to a physical printer?

How can I automate the testing of the printing functionality of my WPF application, including changing common printing properties like paper size, tray, landscape/portrait etc? I'm thinking about using some sort of virtual printer driver like EmfPrinter, but I still have no idea how to verify, for e...
avo
1

votes
2

answer
2k

Views

Unit testing multiple asserts

I am trying to unit test a method in C# using MSTest. I am testing that the password complexity is forced by the ChangePasswordAsync method. My problem is I want to test this method with a range of parameters. Currently i have a unit test with multiple asserts to test the different parameters, is th...
Westy10101
1

votes
2

answer
5.4k

Views

Unit testing WebApi controllers in WebApi

I am trying to unit test my controller, but as soon as this controller uses its embedded UrlHelper object, it throws an ArgumentNullException. The action I'm trying to test is this one: public HttpResponseMessage PostCommandes(Commandes commandes) { if (this.ModelState.IsValid) { this.db.AddCommande...
thomasb
4

votes
2

answer
173

Views

How to get test initialize in memory and use in each test

I'm trying to create Unit Test. I have class User: public class User { public int UsersCount { get { using (MainContext context = new MainContext()) { return context.Users.Count(); } } } public Guid Id { get; set; } = Guid.NewGuid(); public string UserName { get; set; } public string Password { get;...
DIlshod
0

votes
0

answer
3

Views

Webmock: Boxr::BoxrError: 200: File Uploaded get correct return value as error

I'm currently working on a Ruby application using Boxr gem. The gem is use to interact with Box API. I created a Proxy class to make calls to Box API using the Boxr gem. I'm testing uploading a file to box. I created a method upload_file_to_box which pushes a file to a folder on Box. The method is w...
Steven Aguilar
1

votes
1

answer
3.9k

Views

Jasmine spyOn not working

I am fairly new to Jasmine, and I have to test a few function calls: JS CODE object1 = { function1: function() { // object1.function2 is a callback object2.someFunction("called", object1.function2) }, function2: function() { // code to do stuff } } TEST CODE describe("test suite", function(){ it("...
user3077887
1

votes
1

answer
1.4k

Views

xcode - with multiple test targets what does the scheme test do

Im uncertain what the schema test does when clicking on edit schema. My project has multiple test targets. I have tried checking them off in the schema but unchecking them affects nothing. My question is what does the test schema menu really do ?? Here is an image how to get to the schema menu:...
j2emanue
1

votes
2

answer
1.2k

Views

how to use mocking in unit testing in scala

hi i am new in Unit Testing and i want to test it using mock objects .i want to test whether data is successfully stored in mongoDB or not here is my code package models.RegularUserModels import models.UserModels.UserStatus._ // User will give information to Signup class DirectUser() extends Reg...
swaheed
0

votes
1

answer
21

Views

Unit-testing with cats-effect's IO monad

The Scenario In an application I am currently writing I am using cats-effect's IO monad in an IOApp. If started with a command line argument 'debug', I am delegeting my program flow into a debug loop that waits for user input and executes all kinds of debugging-relevant methods. As soon as the devel...
Florian Baierl
0

votes
0

answer
5

Views

How can mock data in state in order to test a Redux reducer which deletes from the state?

How can I add some mock data to the state when testing a reducer in my ReactJS/Redux application? I have this test case: it("should store selected filter", () => { const selectedFilterData = { id: 4321, filterGroupId: 1234, filterName: "gender", text: "Male", value: "pdl_profile_gender_1" } con...
Mr B
0

votes
0

answer
4

Views

Create unit test for function with given parameter

I'm totally new to writing unit tests. I have this function (in abc.test.ts): var fct1 = (param1: string) => { return ("u sent " + param1); }; and I'm trying to write an asynchronous unit test for it using only Mocha. 'till now I have: const asd = require('../abc'); var assert = require('assert');...
user3063909
1

votes
1

answer
875

Views

Google Mock, argument matcher using another argument

Is there any convenient way to match one argument against another one (which is a wildcard)? For example: ON_CALL(calculator_mock, division(_, SameAsArgument).WillByDefault(Return(1.0)) Is there such matcher like SameAsArgument ? UPDATE: maybe SameAsArgument is not very good. What I need is a matche...
1

votes
1

answer
1.6k

Views

How to force a function to throw exception when it invoked with Mocha/Chai

I want to test the function B to catch exception thrown from function A with Mocha/Chai. function A() { // 1. the third party API is called here // some exception may be thrown from it ... // 2. some exception could be thrown here // caused by the logic in this function } function B() { // To catch...
zangw
1

votes
2

answer
350

Views

How to assert that a Rails method will not throw a NoMethodError

In my Rails application I am doing a unit test where I expect an error when calling a certain method. test "sending a logout request while not logged should not return an error" do assert_nothing_raised do do_a_logout end end Problem is that the test keeps reporting as Error instead as of Failure w...
Sam Hax
1

votes
1

answer
3.7k

Views

AngularJS + Jasmine mock unit test $http factory of POST method

How I can make unit-test of $http factory, if it using post method, for example: // controller $scope.logOut = function (){ logOutFactory.logOut().then(function(resp){ }); }; // service app.factory('logOutFactory', ['$http', '$q', 'CONST', function ($http, $q, CONST){ var logoutApiUrl = CONS...
trigger
1

votes
1

answer
2.9k

Views

Unit Testing With Dependency Injection and MOQ

I'm just learning how dependency injection and mocking work, but I'd like some feedback on how I'm setting up a couple of tests. I can get them to pass, but I'm not sure this is all I need. This is an MVC application that makes Web API calls to return data. For this example I'm running queries in...
madvora
1

votes
1

answer
244

Views

How to run same spec with different before hook in rspec

I maintain a gem that gathers data from various APIs. For APIs that require an API key, I have implemented scrapers to fall back on when no API key is set. My current solution to testing both the scraper and the API code is to have two spec files that are virtually the same except for a before hook....
DormoTheNord
1

votes
2

answer
2.8k

Views

Python patch mock appears to be called, but assert fails

I'm using Python 2.6.6 What I'm trying to do is replace the creation of an object with a Mock, to make sure that the correct calls are made. Should be straightforward. My Module: import dir.SubModule class Cls( object ): def Start( self ): self.__obj = dir.SubModule.SubCls() self.__obj.foo() My Tes...
PfunnyGuy
1

votes
1

answer
338

Views

Cypress utilizing Gitlab Variables

I am currently using Cypress as my testing tool, and have been running into a slight problem when running it on gitlab ci. The Problem Part of my Cypress test currently uses sensitive Credit Card Information, so when I uploaded it into a gitlab repository I had to try and figure out a way to keep an...
Lankerd
1

votes
1

answer
778

Views

How can I manually specify source files that Ceedling fails to pick up?

I'm developing a feature for an embedded application and I'm using Ceedling (which builds on top of the Unity test framework) to test it. An issue that I'm having is that I need to use functionality in C source files that Ceedling isn't compiling/linking with my unit test files. According to the Cee...
Tagc
1

votes
1

answer
1.1k

Views

Mocking Angular 2 component dependencies in unit tests

I'm having some difficulty accessing the methods of a mocked service in Angular 2 when unit testing a component. I'm looking for a boilerplate for how to do this and my use case is fairly standard. Having read and tried to follow the Angular docs i'm still getting an issue accessing the methods of...
kojinkai
0

votes
0

answer
5

Views

Data preparation for Unit test - C#

I am writing unit test/Component test using Entity Framework Core InMemory Provider. When I write unit test, I came across with the following question. I have the following two BL/DL methods. ToCreate ToGet So when I write a unit test, I need to create some sample data for the unit test. When I writ...
Jeeva Jsb
1

votes
1

answer
151

Views

Pucharm unittest error: Provide a qualified name of function, class or a module

How to get rid of this annoying error? I do not understand what it want me to do. This happens when I am trying to run a test Clicking on "Run" follows up with the following Screen Clicking on "Continue Anyway" runs the tests normally. So what should I do in order to stop this window from popping up...
Roman
1

votes
3

answer
16

Views

How to test variable scoped in file, from unit test

I have a program like this class A(): def __init__(self): self.foo = x if __name__ == '__main__': x = 96 a=A() print(a.foo) When this runs from the shell "python foo.py" it prints out 96 I also have test_foo.py import foo import unittest class TestFoo(unittest.TestCase): def test1(self): x=37 a=foo...
Vorsprung
-1

votes
0

answer
16

Views

How to make Unit Test return a specific error in Python?

In a Unit Test in Python, how do I make my Unit Test return a specific error like UnboundLocalError or TypeError? Is it like something similar to this? import unittest class TestSounds(unittest.TestCase): def Test(self): self.assertEqual(Sounds([''], ['']), UnboundLocalError)
Anonymous
0

votes
1

answer
9

Views

How to trace code coverage of scripts run in Python shell from an unit test?

I am using Visual Studio Enterprise to take code coverage of unit tests. The unit tests will open a Python shell and execute other Python scripts, for example, run execfile("other_script.py") in the Python shell. How can I make Visual Studio also take coverage from the functions run in other_script....
Kelvin Lui
0

votes
0

answer
36

Views

OnClick = method simulate is meant to be run 1 one = 0 found

Unable to figure out the following error: Using Jest Enzyme - React JS ** Method “simulate” is meant to be run on 1 node. 0 found instead. ** I am trying to test onClick = for props/properties . onClick is called a couple times for this file. I tried to apply the same method that I used f...
user 9191
0

votes
1

answer
19

Views

Skipping private methods during unit test C#

public bool A (UserRequest foo) { ClientRequest boo = B(foo); //Mapping local model to client model C(boo); return result; } I want to write an unit test for method A to test method B but I don't want my unit test to call method C. Method C is a private method but it makes calls to a third party cli...
Sadhurthan
0

votes
0

answer
5

Views

Rerunning groups of tests in xunit for diferent program modes

I have a program which can run in three modes, each of which have somewhat different operational logic, and a different data set. I am adding unit testing to this project using XUnit, and would like to have a set of tests that fires once for each of the program modes. I could do this using [InlineDa...
Jack
1

votes
1

answer
943

Views

Stubbing instance method using Sinon and Mocha

I have written test case for below function (i have left out a lot of unnecessary code and provide only essential stuff but let me know if you need any other info). static getLibs() { return new Promise((resolve, reject) => { const instance = new LibClass(); instance.loadLibs().then((libs) => {...
Bhuwan
1

votes
1

answer
1.2k

Views

How to test a ViewChild/ContentChild property in a angular component?

I have a form container for proper displaying validation errors. I access the form control via ContentChild decorator and manipulate it reactively for building the validation messages. My question is: how can I proper unit test such a component? component.ts import { Component, ContentChild, Input,...
Gabriel Araujo
1

votes
1

answer
37

Views

How to unit test objects that depend on previous values

Over time I've improved my unit testing by refactoring functions so they are pure functions meaning a set of inputs always produces the same output without depending on any sort of state and without causing side effects. Occasionally I encounter scenarios for which I'm not sure how to write good uni...
mitch
0

votes
0

answer
6

Views

How to test this method with jest

I'm struggling a bit to find a solution on how to test this exported function with jest. export const scrollToError = () => { setTimeout(() => { const hasErrorElement = jQuery('.has-error'); if (!hasErrorElement.length) return; jQuery('html,body').animate({ scrollTop: hasErrorElement.offset().top -...
Periback
1

votes
1

answer
1.7k

Views

Mock named exports for testing using Jest

I have a Helper.js file with several helper functions as below that is being used in different components. export function buildOptions(elem) { var oList=[]; for (var i=0; i < field.length; i++) { oList.push ( {options[i][elem]} ) } return oList; } export function B(){ ..... } Here is a comp...
tom

View additional questions