tdd

Mock a method without mocking a class first

六眼飞鱼酱① 提交于 2020-01-23 03:37:26
问题 I am using moq4 for mocking things in my UnitTests . I have a class say TestClass in which a method called TestMethod is their that i wanted to test. So my problem is my TestMethod requires a check on testlist that is in my TestClass. Like this:- public Class TestClass { public readonly ISomeService _someService; public bool TestProperty { get; private set; } public List<string> testlist { get; private set; } Public TestClass(ISomeService someService) { _someService = someService; } public

Sending a POST request with PHPUnit

China☆狼群 提交于 2020-01-22 15:20:12
问题 I have a symfony website, and Im trying to do some unit testing. I have this kind of test where I try to submit something: <?php namespace Acme\AcmeBundle\Tests\Controller; use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; class HomeControllerTest extends WebTestCase { public function testrandomeThings() { $client = static::createClient(); $crawler = $client->request( 'POST', '/', array( "shopNumber" => 0099, "cardNumber" => 231, "cardPIN" => "adasd"), array(), array()); } but I dont think

Can I mock a super class method call?

别来无恙 提交于 2020-01-22 13:37:31
问题 Sometimes, you want to test a class method and you want to do an expectation on a call of a super class method. I did not found a way to do this expectation in java using easymock or jmock (and I think it is not possible). There is a (relative) clean solution, to create a delegate with the super class method logic and then set expectations on it, but I don't know why and when use that solution ¿any ideas/examples? Thanks 回答1: Well, you can if you want to. I don't know if you are familiar with

Can I mock a super class method call?

十年热恋 提交于 2020-01-22 13:36:08
问题 Sometimes, you want to test a class method and you want to do an expectation on a call of a super class method. I did not found a way to do this expectation in java using easymock or jmock (and I think it is not possible). There is a (relative) clean solution, to create a delegate with the super class method logic and then set expectations on it, but I don't know why and when use that solution ¿any ideas/examples? Thanks 回答1: Well, you can if you want to. I don't know if you are familiar with

How to mock specific function in object using Jest?

守給你的承諾、 提交于 2020-01-22 12:33:22
问题 I'm testing a React/Reflux application using Jest. I have the following function in a store: onLoad: function() { console.log("ORIGINAL LOAD"); // http request here } I'm trying to mock it out so that it just does what it needs to do without doing the actual network stuff: beforeEach(function() { // mock out onLoad so instead of making API call the store gets test data PostStore.onLoad = jest.genMockFunction().mockImplementation(function () { var p1 = new Post( "54da7df5119025513400000a", //

Unit Test Help. How do I test for a message output to console?

旧街凉风 提交于 2020-01-21 10:59:06
问题 I am a newbie to unit testing. How do I check the for console output? I have namespace XXShapes { public abstract class XXShape { public virtual void DrawXXShape() { Console.WriteLine("The XXShape was drawn."); } } public class XXCircle : XXShape { public override void DrawXXShape() { Console.WriteLine("The XXCircle was drawn."); } } } namespace XXShapes.Test { [TestFixture] public class XXShapeTest { [Test] public void MyFirstTest() { XXShape s = new XXCircle(); string expected = "The

Unit Test Help. How do I test for a message output to console?

我们两清 提交于 2020-01-21 10:58:48
问题 I am a newbie to unit testing. How do I check the for console output? I have namespace XXShapes { public abstract class XXShape { public virtual void DrawXXShape() { Console.WriteLine("The XXShape was drawn."); } } public class XXCircle : XXShape { public override void DrawXXShape() { Console.WriteLine("The XXCircle was drawn."); } } } namespace XXShapes.Test { [TestFixture] public class XXShapeTest { [Test] public void MyFirstTest() { XXShape s = new XXCircle(); string expected = "The

Moling System.dll

徘徊边缘 提交于 2020-01-21 08:59:45
问题 I need to unit test a method that is using the System.Net.WebClient in the System.dll . I tried to Mole the System.dll , but when I tried to compile the project to add references to the System.dll mole, I got a bunch of errors like the following: Error 2 'System.Net.Moles.SFileWebResponse.Dispose(bool)': no suitable method found to override [C:\DGALibrary\DGALib.IO.Tests\obj\x86\Debug\Moles\s\m.g.csproj] C:\DGALibrary\DGALib.IO.Tests\m.g.cs 251374 33 DGALib.IO.Tests Error 3 'System.Net.Moles

Writing an OS for Motorola 68K processor. Can I emulate it? And can I test-drive OS development?

家住魔仙堡 提交于 2020-01-21 04:28:05
问题 Next term, I'll need to write a basic operating system for Motorola 68K processor as part of a course lab material. Is there a Linux emulator of a basic hardware setup with that processor? So my partners and I can debug quicker on our computers instead of physically restarting the board and stuff. Is it possible to apply test-driven development technique to OS development? Code will be mostly assembly and C. What will be the main difficulties with trying to test-drive this? Any advice on how

How do I unit test persistence?

我怕爱的太早我们不能终老 提交于 2020-01-20 13:33:02
问题 As a novice in practicing test-driven development, I often end up in a quandary as to how to unit test persistence to a database. I know that technically this would be an integration test (not a unit test), but I want to find out the best strategies for the following: Testing queries. Testing inserts. How do I know that the insert that has gone wrong if it fails? I can test it by inserting and then querying, but how can I know that the query wasn't wrong? Testing updates and deletes -- same