Questions tagged [unit-testing]

33950 questions
1

votes
0

answer
47

Views

How to load a specific view controller in KIF tests?

Currently, am navigating through all view controller to reach a specific view controller for testing. But is there a way that I can load a specific view controller for testing that particular page?
fAiSaL
1

votes
1

answer
275

Views

How to setup standalone Controller only once before all test cases in Spring Boot?

I am writing unit tests for controller. I am mocking service layer and using standalone setup for rest controller. ProductSupplierControllerUnitTest.java public class ProductSupplierControllerUnitTest { @Mock private ProductSupplierService productSupplierService; @InjectMocks private ProductSupplier...
Harshit
1

votes
1

answer
71

Views

Django: how to mock a user with FB privilegies

I need to check that the content of a template is loaded properly. However, I need a user that has Facebook integration. This is my view: def profile(request, user_id): '''A user's public pledge settings.''' user = get_object_or_404(SocialUser, pk=user_id) # We only want to show profile pages for us...
lmiguelvargasf
1

votes
0

answer
369

Views

Is it possible to use Jasmine without Karma for testing Angular/Node based Nw.js apps?

I've read ton's of tutorials, but I must admit that this testing stuff is still very confusing to me. I have a Nw.js app which (of course) uses NodeJS and also Angular. I've installed the Jasmine test framework globally via npm and wrote an example test which starts with the following lines, and pla...
Bernd
1

votes
0

answer
395

Views

Mock Component Function in Angular 4

I have one function which I am calling in constructor. Now, in that function I am calling api. As its said that we dont call actual api when we do unit test case. The function which is calling api that is private function. So I am not getting how to mock that function. below is just simple example a...
Nitish
1

votes
0

answer
48

Views

Config transform not working on connection strings in unit test projects

I have a Visual Studio 2017 unit test project with the following App.config: I then add a transform file calling it App.Release.config: So I expect the value of SomeKey to be 'B' and the connection string to be 'ConnectionToDatabase2'. However when I build my test project in Release-configureation I...
Alexander Schmidt
1

votes
1

answer
47

Views

Rhino.Mocks: How to create stub of a class with different assembly fullname

I try to create two mock objects of a class but it creates two mocks with same assembly 'FullName'. public class MyClassA : SomeAbstractClass, ISomeInterface1, ISomeInterface2 { public MyClassA(string someData) : base(someData) { //this property defined in base class CheckId = GetType().FullName; }...
Halit YURTSEVER
1

votes
2

answer
209

Views

How do you do Angular Component Testing with an externally hosted Login?

I have no code to show because currently I dont know where to start. anyone that has done end-to-end testing on an angular app should be familiar with the ng e2e command which spins up a browser and attempts to run tests on the components. The problem is the app I am testing requires you to login vi...
Craig
1

votes
2

answer
743

Views

Slow Karma Unit Tests

I wrote unit tests for a small reach application using Jasmine and Karma.And Karma is running slow for these tests. This is my karma config: var unitTestReportOutputDir = 'unit-test-report'; module.exports = function (config) { config.set({ basePath: '', frameworks: ['jasmine'], reporters: ['dots'],...
zfranciscus
1

votes
1

answer
117

Views

Unit tests not importing project modules (Python)

My code structure is: + project | + - - project_code | | __init__.py | \ main.py | + - - test | __init__.py \ test_main.py In my test_main.py I have: import unittest from project_code.main import MainClass where MainClass is just a class in main.py I then navigate to the project direct...
numberjak
1

votes
0

answer
50

Views

How to test AngularJS controller using Karma-Jasmine

I am trying to use Jasmine and karma to set up unit tests like explained here, in my already developed Angularjs application. I created a simple test file for my controller like this: describe('controller test', function() { beforeEach(module('ipaApp')); var $controller, $rootScope; beforeEach(injec...
Manoj Suthar
1

votes
1

answer
633

Views

Return reference to unique_ptr in google mock

I have problem returning a reference to a unique pointer in google mock. I have an object Foo, with a method operate(), that I’m trying to test in google test/google mock framework: class Foo { public: Foo(BarInterface &bar) : bar{bar} {}; virtual ~Foo() = default; void operate() { bar.getBaz()->s...
Pucko
1

votes
0

answer
385

Views

Running ng test with different test entry point

Is there anyway to run ng test with a different test entry-point to the one specified in .angular-cli.json? https://github.com/angular/angular-cli/issues/8579#issuecomment-346313383 provides a solution for increasing rebuild times by using lazy loaded chunks. But I fear that breaking up the tests in...
Dulitha Ranatunga
1

votes
1

answer
885

Views

How to spy/mock method calls in the constructor of a Angular 5 service?

I have a service, that makes 2 method calls in the constructor: constructor(private http: HttpClient) { this.apiURL = environment.apiURL; this.method(); this.method2().subscribe(); } I'm trying to test this service in the TestBed. However, I am unable to spyOn, using Jasmine's spies, before the Test...
Ka Mok
1

votes
1

answer
95

Views

Angular and Rxjs: writing unit test for filtering on Subject

I have a method in an Angular service like below but I don't know how to write unit test for this function. Can anyone help me with this ? Thank you message$: Subject = new Subject() getMessage(channel: string): Observable { return this.message$.asObservable() .filter(m => m.channel === channel) .ma...
Anh Pham
1

votes
0

answer
232

Views

Karma Unit Test Cordova native Keyboard plugin HTML Doc not defined

When running Unit Tests with Karma I get following error: TypeError: Cannot read property '__zone_symbol__addEventListener' of undefined at Platform.registerListener Users/berfuc/workspace/paysafecash-app/node_modules/ionic-angular/es2015/platform/platform.js:573:1) at Keyboard.focusOutline Users/be...
CodeChimpy
1

votes
1

answer
286

Views

ReactJS/JestJS/Enzyme: How to test graphql() function used in compose()?

This is how I'm testing a very simple reactJS component with react-apollo via jestJS. I'm also using the coverage function of jest. But the coverage shows me, that I'm missing to test the line options: (props) => ({ in the graphql(). How should I do this correctly? Example.js import React, { Compone...
user3142695
1

votes
0

answer
509

Views

Cobertura does not work with Java 9

I have been using Java 8, now trying to upgrade to java 9. Most of the things works except generation of unit test cases report, I am using Cobertura. With Java 9 I get following error, seems like Cobertura still references tools.jar which is removed from Java 9. Failed to execute goal on *****: Co...
Atul Sureka
1

votes
1

answer
49

Views

How to compile test-only code with webpack

I have a few private methods that I want to write unit tests for. However, since these are private methods, they are not exported. This article shows how you can use grunt to wrap a code in comments and this code will be excluded from compiling if you are compiling for production. Is there a simila...
Kousha
1

votes
0

answer
66

Views

Best way to unit test promisified functions with Tape JS?

I'm writing unit tests for promisified code. What's the 'right' way to go about unit testing async code like this? It seems like using timeouts and waiting some arbitrary amount of time for calls to go through is a bad idea for robust testing. Below is some example code for the functions I want to w...
no_parachute44
1

votes
1

answer
145

Views

React ES6 with chai/sinon: Unit testing XHR in component

I have a React utility component that reads the contents of a URL: 'use strict'; export class ReadURL { getContent = (url) => { return new Promise((resolve, reject) => { console.log('Promise') let xhr = new XMLHttpRequest(); xhr.open('GET', url, false); xhr.onreadystatechange = () => { console.log('...
DisasterMan
1

votes
1

answer
50

Views

Unit Test for Service

How do I properly test this method, my test is bellow can someone tell me if its ok or not ? public List findByCategory(String category){ List bookList = bookRepository.findByCategory(category); List activeBookList = new ArrayList(); for (Book book: bookList) { if(book.isActive()) { activeBookList....
valik
1

votes
1

answer
207

Views

CMake unit structure with many tests

I would like to set up cmake to run on a project with unit testing. The project structure is as follows: |---CMakeLists.txt |---build |---source | |---CMakeLists.txt | |---many .cpp and .h files |---tests | |---CMakeLists.txt | |---many .cpp files The source files in tests use Boost unit_tes...
J. D.
1

votes
0

answer
117

Views

How do to configure Karma to NOT restart the browser when it is closed?

I'm using the following command to run my unit tests in sort of a 'debug' mode (where --debug is a custom key I added for my own purposes). karma start ./.config/karma.conf.js --browsers=Chrome --debug The command works fine -- it runs the tests and keeps it's instance of the Chrome browser open ind...
Igor Soloydenko
1

votes
0

answer
17

Views

Mongoose weird error duplication in array of subschemas

I'm testing a couple of schemas using mongoose and I'm getting the same error twice on a subschema. This is my model: const OrderSchema = new Schema({ email: { type: String, required: true, validate: isEmail }, order_code: { type: String, unique: true }, status: { type: Number, required: true }, pro...
Efemorav
1

votes
1

answer
58

Views

Mock rootView of Caliburn.Micro WindowManager

Given I have a method like this: public void ShowDialog() { TestViewModel vm = new TestViewModel(); _windowManager.ShowDialog(vm); DialogResultTest = vm.CoolText; } Now I want to write a test. In that test I want to inject a prepared TestViewModel into the ShowDialog(vm) method. My code looks like t...
Tim Kathete Stadler
1

votes
1

answer
379

Views

Maven Surefire not executing test phase

When running mvn test it appears that surefire is not executing it's test goal (or at the very least is not picking up the tests which I have included within the configuration. This is a multi-module maven project, currently all in groovy, with a structure similar to the below: root -commons -framew...
EJ-K
1

votes
1

answer
49

Views

Create multi entities in Symfony4 Unit tests

Since few days, I'm trying to learn Symfony Unit Test. I made my first test but I noticed one thing : For my first test, I tested a simple implode for some tags : class TagsTransformerTest extends TestCase { public function testTransform() { $tagsArray = [ $this->createTag('Symfony'), $this->createT...
Piface
1

votes
0

answer
42

Views

MSTest Code Coverage with DataRows Not Working

I have a simple convert method from one enum to another. public static ServiceStatus FromTheirState(TheirState fromState) { MyStatus newStatus; switch (fromState) { case TheirState.Online: newStatus = MyStatus.Online; break; case TheirState.Intermittent: newStatus = MyStatus.Intermittent; break; c...
ri chas
1

votes
1

answer
76

Views

Testing file i/o with Perl - frameworks

I have the following command in pl script: mkpath($my_dir,0,0777); I want to test instances when it encounters errors when executing this command. Currently, I change permissions of the parent directory, or some other such change to the file system, to force an error. How would I set up a unit test,...
paulj
1

votes
1

answer
240

Views

Approach to generate Random specimen based on Customization

I want to be able to generate distinct values based on a ICustomization using ISpecimenBuilder.CreateMany. I was wondering what would be the best solution since AutoFixture will generate the same values for all entities. public class FooCustomization : ICustomization { public void Customize(IFixture...
Thiago M
1

votes
1

answer
372

Views

VSTS Maven build - no JUnit tests run

[Update: Problem cause found! read below] Problem: VSTS Maven build does not seem to run JUnit, does not show any JUnit results, does not seem to produce any JUnit testreports. In VSTS, we have a Java project with a Contact and TestContact class with 1 testcase; source\module\src\main\java\nl\custom...
JDG
1

votes
0

answer
351

Views

Mocking fetch POST

I am writing test case for below function: handleShare(response, payload) { ShareUtils.listUsers() .then((users) => { users.forEach(user => userList.push({ name: user.name, id: user.id) }); return SessionUtils.getSessionData(SESSION_ID)); }) .then((sessionData) => { //construct share objec...
Bhuwan
1

votes
0

answer
210

Views

Mocking mongoose validators with jest

I'm testing a mongoose model's validation, while trying to mock a validator, the model still has the reference to the original function, so the validation keeps calling the original function. I want to test that the validator function get's called, however since the validator goes to the db I need t...
Efemorav
1

votes
0

answer
94

Views

DatePickerIOS doesn't like Jest mocked Date()

I'm setting up some Jest testing in my react-native project so i'm setting up snapshots for my components. One of them involves a DatePicker (specifically just time) so I needed to mock a consistent Date() for the snapshots to match. The docs for DatePickerIOS indicate it takes a Date object in the...
MattyK14
1

votes
1

answer
493

Views

spyOn service / component Angular2

I'm trying to implement unit test with service. I'd like some clarification on why this isn't working. setUp for my spec class. beforeEach(() => { fixture = TestBed.createComponent(testComp); service = fixture.debugElement.injector.get(TestService); }); it('mockService', () => { spyOn(service, 'tes...
Kenny
1

votes
1

answer
321

Views

Is tf.Variable a tensor or not?

I've read some answers on this question here and here, however I'm still a bit puzzled by tf.Variable being and/or not being a tf.Tensor. The linked answers deal with a mutability of tf.Variable and mentioning that tf.Variables maintains their states (when instantiated with default parameter traina...
gyre
1

votes
1

answer
368

Views

Angular testing for first time a method which returns Observable

Hello and thank you for your time: I am trying to learn how to test a service which has a method to return an Observable. I have done the Tour of heroes tutorial of the Angular page until the routing module, and I would like to unit test the code. Here is the MyHeroService: import {Injectable} from...
Enoy
1

votes
0

answer
104

Views

Run JUnit 4 Tests Twice With Different Configuration

I have collection of JUnit test classes currently. I would like to run all the tests I currently have but with different configurations. So for instance in my code I have a class: public class Storage { public static final int VERSION = 1; } and I would like to run all my unit tests with Storage.VER...
thatidiotguy
1

votes
0

answer
158

Views

Test passes in Test Explorer, fails in NUnit GUI

I have a special test written in NUnit which passes in Visual Studio Test Explorer but does not pass when it is ran in the NUnit gui. The unit test uses an Interceptor class which swaps two methods so that I can use the second method as a fake for the first which is used in the unit under test. This...
Mootchmonster

View additional questions