Use Moq to see if the method was called with a value

Using Microsoft Visual Studio 2017's built in test with Moq. I have a simple class that creates some content, then sends the content to a notification system. I need to test if the notification system was called, but that the call included some text.

How to test the test method with if and no return

I have a method with following code: public void myMethod() { if (condition1) { doSomething1(); if (condition2) { doSomething2(); } else { doSomething3(); } } } Now doSomething1, doSomething2, doSomething3 are void methods. How to unit-test myMethod

How to call Mockito.given with private method

I found my method using ReflectionUtils Method myMethod=ReflectionUtils.findMethod(myMockClass.getClass(), "myMethod", myArg.class) Now I would like to drive this method to return a specified value. Normally, if myMethod would be public I would

repetition problem of the unit test

Tests are here and they are extremely repetitive, which I would like to change- [TestClass] public class CompareDataTest { private void GenerateTerms(int firstTerm, int secondTerm, out TaughtUnit firstGrade, out TaughtUnit secondGrade) { firstGrade =

How to configure debugging for the system tested in unit tests?

How do you set up debugging so that you can step through your system under test code? I've got this test: [Test] public void GetDeviceSettings_is_called() { //Arrange var mockDeviceInteractions = new Mock<IDeviceInteractions>(); mockDeviceInteractio

Is it OK to change the source for unit testing to work?

I have a method I want to unit test, one that checks for a match between three cards. Because the cards are randomly generated, there's no way to set up three cards that I know will or won't match. I need to do this to unit test my isMatch() method.

make fun of a function in a class method

I want to mock a function which is called within a class method while testing the class method in a Django project. Consider the following structure: app/ def func(): ... return resp # outcome is a HTTPResponse object app/ from app.u

Use Moq to test the unit but the object returns Null

I'm new to using Moq. I am trying to get this unit test to work but my object seems to keep returning null. I saw online that the Setup() must match the actual call. I'm obviously not getting it cause it still doesn't work; it seems to match to me. H

Django simulation requests

I have this function: def function_to_test(..): # some stuff response ="some.url", data={'dome': 'data'}) # some stuff with response I want to make a test, but mocking"some.url", data={'dome': 'data'}) bec

test python compares 2 objects of the same class

In a test, I need to compare that 2 objects of a class have the same values for each of the class attributes. I do not need to compare 2 objects of the class outside of my testing. Is it better to implement the eq in my class (even though the product

Unit Test Creating a SQLite Database Using Spock and Robospock

spock-core:0.7-groovy-2.0 robospock:0.5.0 Android Studio 0.8.2 Fedora release 20 (Heisenbug) This is the complete solution. Now it compiles and runs the unit test successfully, and the directory structure is the same as the preview edit. Please feel

Session Variables for the Unit Test Controller in MVC3

I am unit testing my controller. In one of my controller methods I am setting Session variables: public void Index(){ Session["foo"] = "bar"; return View(); } How can I unit test this? The problem is that the Session property is null w

Vocabulary suitable for Test Case

I am sorry if this doesn't pertain to a specific programming work but it is closely related to writing testing cases. I am in the process of translating IT test cases written in Japanese and I was wondering what are the English equivalent words to de

Mock Verify / VerifyAll before or after the assertion

I have been used to following code pattern while writing my test public void TestMethod_Condition_Output() { //Arrange---------------- Mock<x> temp = new Mock<x>(); temp.setup....... //Act-------------------- classinstance.TestMethod() //Asser

Django FileField test using test devices

I'm trying to build tests for some models that have a FileField. The model looks like this: class SolutionFile(models.Model): ''' A file from a solution. ''' solution = models.ForeignKey(Solution) file = models.FileField(upload_to=make_solution_file_

What is the problem with Stubs for unit testing?

I just watched this funny YouTube Video about unit testing (it's Hitler with fake subtitles chewing out his team for not doing good unit tests--skip it if you're humor impaired) where stubs get roundly criticized. But I don't understand what wrong wi

Is Mocking able to replace built-in features in a method?

I'm trying to define a way to simulate an case on accessing into a database without accessing... That's probably sounds quite crazy, but it's not. Here is an example about a method i would like to test: public IDevice GetDeviceFromRepository(string n

Unit tests with computer-owned states

I am writing a unit test for when my computer receives/makes a phone call. The methods being tested are the events that handle the incoming/outgoing call. If the caller is not an approved caller then the call is rejected. The code works fine, but I c

Theory vs Nunit Test

I was just reading through the Nunit 2.5 docs and came across the Theory attribute, and I'm having a little bit trouble understanding how this is different to a normal unit test and how it could be used. What makes it different from a normal test? Wh

XNA unit tests: should I mock my GraphicsDevice

I'm fooling around with the XNA framework. To help me around I made a helper class that looks like this: ActorHolder + SpriteBatch (SpriteBatch) + ContentManager (ContentManager) - drawables (IList<IDrawable>) - updatables (IList<IUpdatable>)

What to test in unit tests, a method or a scenario?

What to test in unit testing, a method or a scenario? If test each method then minimal test case setup is required. If test a method which calls other methods then setup required for the test case is huge. If unit-tests for the individual methods are