Questions tagged [testing]

55657 questions
1

votes
1

answer
12

Views

How can test MutableLiveData<>.observe when the data is changed?

I have the next code for test if the API is working with Login function: @RunWith(RobolectricTestRunner.class) public class LoginTest { LoginRespository profileRepository = new LoginRespository(RuntimeEnvironment.application); @Test public void testLogin() { MutableLiveData data = new MutableLiveDat...
Tlaloc-ES
1

votes
2

answer
216

Views

Unit Testing valid inputs to a method

The question is whether it is bad practice to have a method in your Application project that has no other purpose than to generate data for your test project. I have a unit test that I am using to do a cursory exam to ensure that all valid inputs will run through the primary method of my application...
TimidObserver
0

votes
0

answer
4

Views

GHC sanity test doesn't work error in test 6

I've recently been trying to use haskell-stack, but whenever i try to do stack setup i get The GHC located at /root/.stack/programs/x86_64-linux/ghc- 8.2.2/bin/ghc failed to compile a sanity check. Please see: http://docs.haskellstack.org/en/stable/install_and_upgrade/ for more information. Excepti...
MS B
1

votes
2

answer
338

Views

Custom User Testing in Django

I have a Django application and the custom user - want to test it (do unit testing). My custom user is emailuser, which consists of e-mail and password fields. I want to set up something of such national mplayer, give it a field and a password. But my code below does not work. settings.py AUTH_USER_...
mark
1

votes
1

answer
383

Views

MVC 5 Unit tests vs integration tests

I'm currently working a MVC 5 project using Entity Framework 5 (I may switch to 6 soon). I use database first and MySQL with an existing database (with about 40 tables). This project started as a “proof of concept” and now my company decided to go with the software I'm developing. I am strugglin...
Pierre
1

votes
1

answer
686

Views

pytest: If a crash/segfault/etc. occurs during testing, is there a way to make pytest log the crash as a test failure and continue testing?

I have a few unit tests written using pytest that have successfully caused segfaults to occur. However if a segfault occurs (on my Mac) during these execution, pytest seems to quit altogether and provide no information on what caused the python interpreter to crash. Now I could infer from the logs t...
nonbot
0

votes
0

answer
11

Views

Is there any good reason to catch exceptions in unittest transactions?

The unittest module is extremely good to detect problems in code. I understand the idea of isolating and testing parts of code with assertions: self.assertEqual(web_page_view.func, web_page_url) But besides these assertions you also might have some logic before it, in the same test method, that coul...
1

votes
2

answer
757

Views

Why can't I see any console or trace output when running load tests in VS 2015?

I've got DEBUG and TRACE defined. I've tried Trace.WriteLine, Debug.WriteLine, Console.WriteLine, and TestContext.WriteLine. In the Test Results window, I've added columns for Output (StdOut), Errors (StdError), Debug Trace, and Stack Trace. I've tried all the 'Show output from' options available...
Paul Kienitz
1

votes
3

answer
1.4k

Views

PyTest: test which function was called in the if statement

I have a function, which considers three different cases and for each case calls a different function, like in the example below def my_fun(input): if input == 1: fun1() if input == 2: fun2() if input == 3: fun3() I would like to write a test for function my_fun using py.test, but I don't know how I...
Ziva
1

votes
2

answer
3k

Views

Android. @RunWith(AndroidJUnit4.class) - cannot resolve in package “androidTest”

Android Studion 2.2.3 Install Android Support Repository - ver. 44.0.0 I setup all as in official site for Espresso: https://google.github.io/android-testing-support-library/docs/espresso/setup/index.html I try to write instrumentation test (Espresso) in package androidTest. So I create StringUtilAn...
Alexei
0

votes
0

answer
7

Views

pytest-4.x.x: How to report SKIPPED tests like XFAILED?

When a test is xfailed the reason that is printed reports about test file, test class and test case, while the skipped test case reports only test file and a line where skip is called. Here is a test example: #!/usr/bin/env pytest import pytest @pytest.mark.xfail(reason='Reason of failure') def test...
Ashot Vantsyan
1

votes
0

answer
9

Views

How to get the list of all @Test annotation methods from test source package

I'm working on a project where in all the test classes in a package will populate in UI where in I can select any of the class and run. Now I want to extend it to test methods run. For this I need to retrieve all test methods in a test class.I found following class which will give me test classes...
Tanusha Raha
1

votes
2

answer
1.5k

Views

Ionic 2 : Test with jasmine and karma error 'ng test'

I try to follow this tutorial : http://lathonez.com/2017/ionic-2-unit-testing/ And when I run 'ng test' I have this error : C:\xampp\htdocs\AppFineMobile>ng test 27 03 2017 11:55:00.556:ERROR [preprocess]: Can not load 'angular-cli', it is not registered! Perhaps you are missing some plugin? No pr...
V. Pivet
1

votes
2

answer
1.4k

Views

How to perform assertion on all remaining elements in StepVerifier?

StepVerifier has an assertNext method that allows performing an assertion on a value of next element. StepVerifier.create(dataFlux) .assertNext(v -> checkValue(v) .verifyComplete(); What is a good way to perform assertion for every remaining element (e.g. to check that every element is positive)? I'...
Dmitriusan
1

votes
1

answer
824

Views

Angular unit test error: Unexpected value 'ObservableMedia' imported by the module 'DynamicTestModule'

I have a fairly simple unit test file like so: import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core'; import { async, ComponentFixture, TestBed } from '@angular/core/testing'; import { Http, HttpModule } from '@angular/http'; import { MockBackend } from '@angular/http/testing'; import { MaterialMod...
isherwood
1

votes
2

answer
1.4k

Views

Angular2 Unit test for Observable.interval

I have a service that polls data from server every 500 milliseconds. For this i have used Observable.interval(). Below is my code. I want to write the unit test for this service service.ts: pollData() { Observable.interval(500).mergeMap(() => this._http .get(url, { headers: headers }) .map((resp: Re...
user1722632
0

votes
0

answer
4

Views

React-Testing-Library - Wrapping Component with Redux and Router

I am trying to setup an test file to render a route/page on my application. I'm trying to wrap everything with Redux and Router, and this is what I have: import React from 'react'; import { render } from 'react-testing-library'; import { createStore } from 'redux'; import { Provider } from 'react-re...
Phillip
1

votes
0

answer
16

Views

AngularJS unit testing Karma - unknown provider

I am trying to set up unit tests on our legacy AngularJS app. I am using the standard karma along with angular-mock to set up the tests cases. But I am getting issues with Unknown provider when I am trying to inject some services and factory. My karma.conf looks something like this (I have removed a...
Tushar Chutani
1

votes
2

answer
522

Views

How to test document clicks in unit tests in angular

We have a drop-down component that has its dropdown collapsed on any outside click. This is implemented as: @HostListener('document:click', ['$event']) public documentClick(event) { if (this.dropdownIsOpen && !event.clickedFromMe) { this.dropdownIsOpen = false; } } How can this code be tested? When...
splintor
1

votes
1

answer
1.6k

Views

Process of testing with TypeORM and Nestjs, and jest using mocks?

This question can likely be generalized to stubbing repositories in a service and how to properly test and provide coverage in the context of this question. I am in the process of learning more about testing, but am stuck with how to properly perform testing that involves the DB. I have a User ent...
kyle
1

votes
3

answer
62

Views

How to assert that a method call was not made, without any_instance?

I have a class, that in one situation should call :my_method, but in another situation must not call method :my_method. I would like to test both cases. Also, I would like the test to document the cases when :my_method should not be called. Using any_instance is generally discouraged, so I would be...
Matilda Smeds
1

votes
3

answer
235

Views

Katalon WebUI.SetMaskedText() randomly wrapping text

I have a field in a popup to enter a phone number with masked text: '( _ _ _ ) _ _ _ - _ _ _ _'. (Masked text means that we are using jquery to automatically format the text being entered. You can learn more here.) The underscores above are just to represent the spaces for the digits of the phone n...
nnewren
1

votes
2

answer
1.3k

Views

How can I resolve Angular unit test error: “An error was thrown in afterAll\n[object ErrorEvent] thrown”

When I run ng test command in my angular project has error, it gives an error like that 10% building modules 1/1 modules 0 active04 12 2018 11:29:43.408:WARN [karma]: No captured browser, open http://localhost:9876/ 04 12 2018 11:29:43.414:INFO [karma]: Karma v2.0.0 server started at http://0.0.0.0:...
Samet ÇELİKBIÇAK
1

votes
1

answer
52

Views

JEST: select an HTML element through innerHTML

Folks, I have a React Component which on rendering has this HTML in it: 1 It's a pagination button, and I want to simulate a click on it. The hacky way to select this element was: const wrapper = Enzyme.mount(); wrapper.find('button.encryped-class__2TKgPzyme4') .first() .simulate('click'); I want to...
darth-coder
1

votes
2

answer
117

Views

Download file - Save popup in Internet Explorer using TestCafe

In Internet Explorer, whenever a download file window is asking for three options 1. Open 2. Save 3. Close Due to company policy, can't disable popup. However, need to handle same in TestCafe automation. What to click save/save as option? Request for a solution.
Hiruthere
1

votes
2

answer
38

Views

Separate locators in .json file - Cypres

Is it possible to separate locators in .json file while working with Cypress? I can't seem to find anything about this online, but it seems like something that should be possible. I separated my locator in a .json file but I have problems with calling them in my tests.
beginner501
1

votes
1

answer
1.2k

Views

How to mock the new HttpClientFactory in .NET Core 2.1 using Moq

.NET Core 2.1 comes with this new factory called HTTPClientFactory, but I can't figure out how to mock it to unit test some methods that include REST service calls. The factory is being injected using .NET Core IoC container, and what the method does is create a new client from the factory: var clie...
Mauricio Atanache
1

votes
1

answer
76

Views

How can I unit test an Asynchronous method in F#?

I've got a method that returns a task I'm trying to test synchonously in F#. Here's the method, which is an implementation of a C# interface: member this.RunAsync(): System.Threading.Tasks.Task = async{ this._settings.LogSettings |> Seq.iter(fun settings -> this.clearLogs(settings)) |>...
reckface
1

votes
1

answer
30

Views

Using Moq to test call to different class

The problem I have the following method: public void ParseRebootData(RebootDeviceDto rebootDeviceDto) { if (rebootDeviceDto.RebootAtUtc.CompareTo(DateTime.UtcNow)
Devator
1

votes
2

answer
36

Views

I Need help finding a list of non-functional requirement benchmarks?

I am doing a course on Non-functional testing and I need to find and test an open source program. I have found a ton of programs that I would like to use but unfortunately, not many of the programs come with the non-functional requirements which I need. Can someone who works with creating these pro...
1

votes
2

answer
52

Views

Perform sanity check before running tests with pytest

I would like to perform some sanity check when I run tests using pytest. Typically, I want to check that some executables are accessible to the tests, and that the options provided by the user on the command-line are valid. The closest thing I found was to use a fixture such as: @pytest.fixture(sco...
Nemo
1

votes
2

answer
84

Views

TestMain - no tests to run

I am writing a package which compiles a C source file and writes the output to another file. I am writing tests for this package, and I need to create a temporary directory to write the output files. I am using TestMain function to do this. For some reason, I always get the warning 'no tests to run'...
Sriram Kailasam
1

votes
2

answer
71

Views

How to unit test a UIButton that calls an asynchronous task

I am trying to test a login method triggered by a IBAction that if the login failed (if the completion hander returned a error), I want to present an alert controller, but the login method is obviously an asynchronous. The loginUser method is already mocked and always returns handler(nil, .EmptyData...
Brendon Cheung
1

votes
2

answer
47

Views

MSTest ThrowsException with conditions on the exception object?

I'm using MSTest Assert.ThrowsException, but sometimes I want to add test conditions on the thrown exception object, e.g. checking that the message mentions a specific phrase, identifier, data value or whatever. The best solution I've found is a construct that doesn't use Assert.ThrowsException, but...
Kjell Rilbe
1

votes
3

answer
52

Views

How can I test if a private method of a class is called or not with rhino mock?

I am quite new at C# and also rhino mocks. I searched and found similar topics with my question but couldnt find a proper solution. I am trying to understand if the private method is called or not in my unit test. I am using rhino mock, read many files about it, some of them just say that change t...
SSanc
1

votes
3

answer
45

Views

Relationship between Unit Testing & End-to-End (Integration per se) while following BDD

My question is also related to who does what in typical BDD. My understanding, Product owner comes up with User Story (may or may not in Gherkin), QA writes Scenarios for End-to-End testing(in feature files), Dev writes his code (how and where, does he follow BDD as well?). At this point if the Dev...
Anup
1

votes
1

answer
45

Views

How can I mock a simple method using Moq framework?

Let's say I've a simple method which checks whether the passed number is Even & returns a boolean value. I'm new to mocking & trying it out. How can I mock this method using Moq framework? public bool isEven(int x) { bool result = (x % 2 == 0) ? true : false; return result; }
Tim Smith
1

votes
1

answer
63

Views

How to unit test return value of function - Angular (Jasmine/Karma)

I am wondering if there is a way to correctly test the return value of a function in Angular. I want to essential test the return value to be true for one test and write another to test the opposite scenario. Ts component: get() { if (this.object == undefined) { return true; } else { return false;...
thenolin
1

votes
1

answer
50

Views

How to locate/click selector (button) using testcafe

I am trying to test the submission of an application using testcafe. However, I don’t seem to be able to get testcafe to click the ‘Submit Application’. I have tried the following so far: .click(Selector('button').withText('Submit Applicaition')) .click('#submit-application').withText('Submit...
Milka
4

votes
1

answer
163

Views

Jest - How to get coverage for mocked classes and implementations

I'm currently working on a project where I'm using Jest for unit testing and code coverage. Everything is working fine, except coverage for mocked classes/methods. I don't seem to get the desired coverage results. I've tried to find something in the Jest docs and searched online for an answer, but I...

View additional questions