tdd

How would you unit test data annotations?

一世执手 提交于 2019-11-29 10:58:55
Two of the class properties have the following annotations: [Key] [Column] [Required] [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public int Id { get; set; } [MaxLength(25)] public string Name { get; set; } I understand that testing Key, Column and Required attributes is no longer a unit test, it's an integration test as it would depend on the underlying database, but how do you go about testing MaxLength(25) attribute? One of the alternatives that I can think of, is to add a code contract into the property. Update As suggested, I wrote the following helper: public class

Simulating user input for TDD JavaScript

喜欢而已 提交于 2019-11-29 10:48:32
I'm finding it increasingly difficult to simulate actual user events using jQuery or native element trigger functions. For example, if you have a text input and you don't want the user to be able to add a character, you can call e.preventDefault() with the jQuery-normalised event object on the keydown event. However, there is no way to programatically verify this test scenario. The following test passes even without the call to preventDefault because the jQuery keydown trigger isn't a "real" event. input.val('test').trigger(jQuery.Event({ which: 68 }); expect(input).toHaveValue('test');

How to mock File in javascript?

…衆ロ難τιáo~ 提交于 2019-11-29 10:43:38
问题 I'm developing some small project to exercise my TDD skills. The project consists of an audio player which has the ability to drag'n'drop files in a playlist. I'm using Jasmine as a testing framework. The problem I faced is that I can't mock javascript files to test my file upload functionality. I tried to create a File like this: new File(new Blob(), "name"); but Chrome does not allow creating files manually. File's constructor is illegal to use. I found a solution with grunt.js which

Detecting console.log() calls

随声附和 提交于 2019-11-29 10:28:46
问题 I'm trying to write a test case for a debugging method that writes messages to the JavaScript console using console.log() . The test has to check that the message has been successfully written to the console. I'm using jQuery. Is there a way to attach a hook to console.log() or otherwise check that a message has been written to the console, or any other suggestions on how to write the test case? 回答1: console.log doesn't keep a record of messages that are logged, or emit any events that you

Can I test method call order with AAA syntax in Rhino-Mocks 3.6?

梦想与她 提交于 2019-11-29 09:46:06
Is it possible to test for the following example if the Method1 called 1st, then Method2 called after and then Method3 by using the AAA syntax, in Rhino-mocks 3.6 ? // Assert var mock = MockRepository.GenerateMock<ISomeService>(); // Act myObject.Service = mock; // How should I change this part to ensure that Rhino Mocks check the call order as well? mock.AssertWasCalled(m=>m.Method1()); mock.AssertWasCalled(m=>m.Method2()); mock.AssertWasCalled(m=>m.Method3()); Here's one way to do it... mock.AssertWasCalled(m=>m.Method1(), options => options.WhenCalled(w => mockService.AssertWasNotCalled(x=

Does C1 code coverage analysis exist for Ruby? [closed]

こ雲淡風輕ζ 提交于 2019-11-29 09:43:39
问题 I'm currently using Rcov to get C0 code coverage analysis for a rails project that I'm working on. However, those results are practically meaningless- I have 100% coverage according to rcov (as it only covers C0 analysis) and I've barely written half the test cases for the functionality that exists thus far. I'm used to the useful results from the code coverage in Visual Studio 2008 Team, which has C1 coverage. Are there any tools that provide similar coverage for ruby? 回答1: At the moment,

In TDD, why OpenEJB and why Arquillian?

喜欢而已 提交于 2019-11-29 09:35:28
问题 I'm a web developer ended up in some Java EE development (Richfaces, Seam 2, EJB 3.1, JPA). To test JPA I use hypersonic and Mockito. But I lack deeper EJB knowledge. Some may argue that we should use OpenEJB and Arquillian, but for what? When do I need to do container dependent tests? What are the possible test scenarios where I need OpenEJB and Arquillian? Please enlighten me :) 回答1: There are two aspects in this case. Unit tests . These are intended to be very fast (execute the whole test

MSTEST - async Testinitialize guarantee test fail

风流意气都作罢 提交于 2019-11-29 09:23:04
Just wondering, if anyone thought like this: This is incorrect design to have async call within TestInitialize, as TestInitialize has to happen before any TestMethod. Can this be correct approach in any way to have async TestInitialize as well? private int val = 0; [TestInitialize] public async Task TestMehod1() { var result = await LongRunningMethod(); val = 10; } [TestMethod] public void TestMehod2() { Assert.AreEqual(10, val); } any thought? Stephen Cleary Probably the cleanest way to do this is to have TestInitialize start the asynchronous operation, as such: [TestClass] public class

MSTest Code Coverage

自作多情 提交于 2019-11-29 09:08:26
Is there a way to test code coverage within visual studio if I'm using MSTest? Or do I have to buy NCover? Is the NCover Enterprise worth the money or are the old betas good enough if Microsoft doesn't provide built in tools to do code coverage? EDIT: Description of VS Products and which ones include code coverage https://www.visualstudio.com/vs/compare/ TestDriven.NET ( http://testdriven.net/ ) can be used if your VS version doesn't support it. Yes, you can find code coverage information from within Visual Studio, provided that you have a version of Visual Studio that provides that

Unit Testing a large method

拟墨画扇 提交于 2019-11-29 07:20:35
Following Test-Driven Development that is. I've recently implemented a algorithm (A*) that required a clean interface. By clean all I want is a couple of properties and a single search method. What I've found hard is testing the search method. It contains around five steps but I'm essentially forced to code this method in one big go which makes things hard. Is there any advice for this? Edit I'm using C#. No I don't have the code at hand at the moment. My problem relies in the fact a test only passes after implementing the whole search method - rather than a step in the algorithm. I naturally