Most voted "unit-testing" questions
Unit testing or unit testing is a method by which individual source code units, assemblies of one or more computer program modules, together with associated control data, operating procedures and operating procedures, are tested to determine if they are fit for use.
Learn more…165 questions
Sort by count of
-
2
votes2
answers294
viewsHow does Junit work?
How does the Junit open-source framework work? Does it guarantee the quality of the software? It is recommended to write unit tests on a daily basis?
-
2
votes1
answer200
viewsHow to return the value according to the received parameter?
I had to mock with DAO, but the method receives a spreadsheet object and according to the id attribute of the Spreadsheet I need to return a different value. How do I do this to correctly compare…
-
2
votes1
answer1483
viewsCreate a mock for any instance of a class
How do I mock any instance of a class? I would like to do this so I don’t have to mock an object and have to put it inside a class. Example: [TestFixture] public class TokenTest { GeradorDeToken…
-
2
votes2
answers441
viewsShould I cover private methods in unit testing?
In my unit testing coverage, private functions are not tested. I don’t know if this is the right route. Should I test my private methods? All? No. NET, the attribute InternalsVisibleTo makes it…
-
2
votes1
answer339
viewsUnit test of a javascript fetch function with jest or mocha
I’m starting studies with TDD and came across a function like this: const fetchexample = callback => { fetch('/token', { method: 'POST', body: 'user=teste' }).then(res => res.json()).then(json…
-
2
votes0
answers108
viewsPlugin Execution not covered by Lifecycle Configuration
I have implemented unit tests in my application using Jasmine and I want to configure a continuous integration in Maven so that the tests run automatically. Already working, however an error is…
-
2
votes0
answers84
viewsFacebook page does not open with click - Nightwatch
Hello, I recently started working with Nightwatch.js. I want to test the facebook icon. The code is this: module.exports = { "Facebook link" : function (browser) { browser…
-
2
votes2
answers895
viewsJunit unit test for default system routines
I have a Java code that checks if there are standard categories registered in the database, if yes it returns true, if he doesn’t return false. public boolean validaEntradaDeDadosPadrao() {…
-
2
votes1
answer374
viewsHow to test java exceptions using spring and Junit 5 lib?
I’m in doubt about how to test my java exceptions using the Spring Framework’s own resources. I’m testing a class called UsuarioValidator.java and in it I have a method called…
-
2
votes1
answer478
viewsStatic properties and memory release
I’m having some doubts regarding the release of resources for cases where my modifiers are static. My project is unit test and I’m using Selenium for the first time. public class LoginTest : Base {…
-
2
votes1
answer253
viewsWhen should a utility class become an injectable dependency?
I often write small utility classes to solve some minor problem in my code. For example (I will use Spring for DI): @Service class PessoaService { public PessoaResponse converter(Pessoa pessoa, Long…
-
2
votes0
answers94
viewsA help with Spring Boot Annotations
A help with Annotations ... Today my tests are like this : @ConfigA @ConfigB @ConfigC @ConfigD public class MeuTesteA {} @ConfigA @ConfigB @ConfigC @ConfigD public class MeuTesteB {} See, I have to…
-
2
votes1
answer60
viewsError debugging by null on connection
I want to document a unit test but I’m getting error: System.Exception: 'Error closing database connection: Undefined object reference for an instance of an object.' My test case was so coded: using…
-
2
votes1
answer276
viewsEnsure that the unit test is validated in an IF. Unit Test
I need to create a unit test that validates the following code. But how can I guarantee that the test validates the downloaded and downloaded content? if not (os.path.exists(filename)):…
-
2
votes1
answer2219
viewsAssertThat method and use of Matcher
To perform unit tests using the method assertThat in Junit, you need to pass an object Matcher as a parameter. public void assertThat(Object o, Matcher matcher){ ... } An example of using passing an…
-
2
votes1
answer77
viewsphpunit no phpstorm
I’ll run unit tests for phpunit in my stage and I can’t put it in the project. I added the file composer.json and when I will try to add dependency phpunit/phpunit, it presents the following error:…
-
1
votes1
answer86
viewsHow to test a Singleton class in Ruby?
I’m using require "Singleton" to make a certain class only be instantiated once. However, when running rspec tests, I get the following error: Nomethoderror: private method `new' called for…
-
1
votes1
answer975
viewsHow to test a DAO (using Spring and JPA) out of a container?
I am developing an application with JPA 2, Spring and JSF 2 running in Wildfly 8.0.0. I have developed some previous applications following this same specification but never tested properly using…
-
1
votes1
answer1739
viewsHow to perform tests on private methods using Mockito
this weekend I read about the Mockito and double tests, and I came up with the following idea. Test private methods with this framework. I saw that the PowerMock performs such a procedure, but…
-
1
votes1
answer422
viewsMockito-Android Test return method
I’m trying to test a return of a method from my class on an Android project. I’m doing it this way: MyClass var = Mockito.mock(MyClass.class); With this, I already have my instance. Now I need to…
-
1
votes3
answers332
viewsIs it recommended to test model validations?
My experience is with Ruby on Rails, but I believe my question will be for other cases. The ORM Activerecord (from Rails) allows validating in fields things like: Presence Oneness Size (of a string)…
-
1
votes1
answer68
viewsProblem running test controller in Rails 4
Good afternoon, I generated a scaffold of a class of mine, User example. While running the tests I came across the following failure: Minitest::Assertion: "User.count" didn't change by 1. Expected:…
-
1
votes2
answers421
viewsWhat is TDD and what is it for?
I was taking a look at PHPUnit - which is a unit testing framework . Taking a look at some tutorials, I came across a term called TDD. What comes to be TDD? And what’s his use in day-to-day…
-
1
votes1
answer43
viewsHow to deal with the requirement of certain attributes in models that include a Concern in Rails?
I’m working on a project where I have several models who share the behavior of being approvable. After doing some research, I came to the conclusion that the best thing in this case is to use the…
-
1
votes1
answer130
viewsIs it correct to implement unit test in the model in the context of the Python language?
In some languages it is not suitable. I would like to know if python is different. Thank you.
-
1
votes3
answers1748
viewsTest a constructor with more than one parameter
I am trying to create a test class for my constructor, but it receives three parameters and these parameters are validated within the class itself, to allow or not the creation of its instance.…
-
1
votes1
answer144
viewsAssert.Areequal() fails when everything seems to be right
I can’t find any errors in my Bubble Sort algorithm. But the assert returns error. I’m passing wrong arguments to the Assert.AreEqual()? //The method for testing public static int[] BubbleSort(int[]…
-
1
votes0
answers261
viewsChromedriver.exe error using Coypu for Selenium
I’m making an app, to test this framework unit test. However, it indicates an error that cannot find the path where Chromedriver.exe is, the same is found in the folder I indicated. Here follows my…
-
1
votes0
answers74
viewsProblem creating android unit test with Rxjava and Mockito
The test is about making the assertions that the methods are called when the execution is successful, but an error is occurring that I cannot solve. My class: class LoginActivityPresenter(private…
-
1
votes1
answer768
viewsTest main class input method with Systemin drive in test class
As I test the System.out.println() a method? The method I want to test displays the phrase: Enter the name > How do I test whether or not this phrase has been changed in the Test? main class:…
-
1
votes0
answers36
viewsInclude Javascript files that the test depends on to run in Mochajs
I’m developing a client-side Javascript application, and I want to run some tests using Mochajs, only that the test depends on several Javascript files to run, which are in different folders, for…
-
1
votes0
answers35
viewsUnitary test for filter application
I want to create a unitary test for the method: public BufferedImage negativo(BufferedImage image) { int width = image.getWidth(); int height = image.getHeight(); for (int i = 0; i < width; i++)…
-
1
votes1
answer165
viewsDoubts with DAO method
I have a question on the issue of a generic DAO, being used in a test project with Vraptor. This dao, works normal in my requests, more when being used in a unit test the same as the following…
-
1
votes1
answer33
viewsDo you run a negative test?
In my case I am using Postman to do the Integration tests, something very simple so far. However my doubt is, if just as in Unity test (In case I have already done several with Mstest c#) whether it…
-
1
votes1
answer36
viewsHow to check the type of a unit test value using Jest?
I have a function that returns an object with two properties: name and id, where name will receive its value per parameter and id is generated automatically by Date.now(). My goal is to create a…
-
1
votes1
answer110
viewsCode line in Unit Test that is not accepted by code coverage
I have a test routine where a certain line of code is not accepted by the coverage. This is a test to return Defaultvalue since the object calling it is null. This is the method being tested public…
-
1
votes0
answers58
viewsHow to inject a Factory when creating a unit test with Angularjs?
good afternoon! I am creating a unit test for my controller and the same is giving the following error: Typeerror: Cannot read Property 'saveUser' of Undefined At Scope.UserFormCtrl.$Scope.save I…
-
1
votes0
answers36
viewsDoubt with Phpunit Unit Tests
Guys I’m starting with Phpunit, I’m implementing the first tests in my applications but I’m with the following doubt. All classes should actually be tested, or there are some exceptions, if yes…
-
1
votes0
answers27
viewsHow to generate Factory Boy Fuzzy Attribute before running each test?
I am creating unit tests to perform integration tests of my web application. The tools I am using are: Mongomock to create a temporary bank instance for testing and Factory Boy to create mock…
-
1
votes1
answer587
viewsMock non-static method of a class containing a call from another static method
Hello, The title got a little fuzzy, but come on. I have the class below: public class ClasseA { public static final int constA = ClasseB.metodoB(); public int metodoA(){ System.out.println("Passei…
-
1
votes0
answers182
viewsUnit Testing - How to test a Try-with-Resources?
I would like to know the best way - or the standard way - to test a Try-with-Resources; with Test Cases for each of the Exceptions that can be launched (simulating the release of each of these…
-
1
votes1
answer874
viewsUnit Tests in Controller mocking EF Context
I’m not getting a solution on how to test my application (mocking the EF context) EF context: public class SawluxContexto : DbContext { public DbSet<Restaurante> Restaurante { get; set; }…
-
1
votes1
answer26
viewsRuby unit test does not work
I am running a simple unit test and on my machine it does not show whether the test ran successfully or error. My code below should give a flaw. require 'minitest/autorun' class MagicBallTest <…
-
1
votes1
answer183
viewsUnit Test - How to verify an expected error?
In a unit test for a module using Mocha and Chai need to check if an error is returned if the parameter format is invalid. The function of the module in question returns a Promise. The example below…
-
1
votes0
answers286
viewsError when testing GET method with Jasmine/Angular
I am trying to compare the type of method when there is a call with the api url. import { async, ComponentFixture, TestBed, getTestBed } from '@angular/core/testing'; import {…
-
1
votes0
answers239
viewsunit test with mocked Json
I am trying to create a test from a json file that I have with the mocks of the Api response. But when I run the unit test the variable stream the return is null, ie it can’t read the file resulting…
-
1
votes0
answers666
viewsHow to test one method that depends on the result of another with Junit?
Greetings, I have a class that does actions in an email. I created some tests for this class and would like to know if this is a valid form of testing or if there is any better way to do it. I test…
-
1
votes1
answer191
viewsTest of default in Angulajs application using Karma and Jasmine
Hello, I have an application in Angularjs and I wanted to ensure the quality of my code by doing unit tests and I am using Karma and Jasmine for this. After having had a certain difficulty to…
-
1
votes1
answer644
viewsUnit Service Testing Using Karma (typescript/angular)
I’m trying to test a service GET method: get(url: string, params?: any): Observable<Response> { let options = {}; this.securityService.setHeaders(options); if (params) this.setParams(options,…
-
1
votes0
answers71
viewsMoq in c# methods of different classes
Good night. I’m new to unit testing. I’d like to ask for help to resolve a question. I have the following method of a class that calls the method of another class: class public Teste: ITeste {…