Tag Archives: testing

C# Unit Testing – Ensure That Loop Continues Until Valid Input is Given

Questions: I have the following code that asks the user for input and continues asking until they give valid input. The user input is received via Console.ReadLine public int ChooseMove() { string input; do { input = ui.AskUserForInput(); } while (!ValidateInput(input)); return int.Parse(input); } private bool ValidateInput(string input) { string [] positions = ui.GetValidInputs(); if… Read More »

Testing PopUpMenu with Robolectric

Questions: I have an Image on click of which I display a PopUpMenu. I am not getting any way to test that particular pop up menu that is being displayed. I have two buttons 1) Edit , 2) Delete and what I want to test is the click of the Delete and the edit. Any… Read More »

Testing string for decimals for calculator

Questions: I have an array called userInput that I am pushing my input to eventually perform an eval() calculation on. I am adding the decimal function but need to test if a number already has a decimal in my array to avoid something like 3.00.00.00. My current function function addPeriod() { if((inputArray.length == 0) ||… Read More »

Testing State Objects in React

Questions: I’ve seen this question and it’s helped with my understanding of how to set state correctly, but I’m struggling with the correct format of testing state based on a variable. For example, I have this setState function call with a newItem variable: addToSandwich(newItem){ setState(prevState => { return { sandwichItems: {…prevState.sandwichItems, [newItem]: true} }; });… Read More »

.Net Core Identity Unit Testing – Add Data To Mocked UserStore

Questions: I’m currently trying to unit test my Auth service that uses UserManager and Role Manager from Microsoft.AspNetCore.Identity. I have a few tests up and running by using the code below. I mock the UserStore but don’t add any data to it. var dbContextMock = new Mock<ApplicationDbContext>(); var mockUserManager = new Mock<UserManager<ApplicationUser>>( new Mock<IUserStore<ApplicationUser>>().Object, null,… Read More »

Testing an objects property change within a spec with karma-jasmine

Questions: I’m trying to test a simple object and track its own properties changed by its own methods. Somehow the value of the property isn’t changing after launching the methods: it(‘extending an object with new properties’, function() { var newCar = Object.create(car); newCar.climatronicOn = false; newCar.startClimatronic = function(){ newCar.climatronicOn = true; } newCar.stopClimatronic = function(){… Read More »

C# testing to see if a string is an integer?

Questions: I’m just curios as to whether there is something built into either the c# language or the .net framework that tests to see if something is an integer if (x is an int) // Do something It seems to me that there might be, but I am only a first-year programming student, so I… Read More »