tdd

Should an Aggregate Root Implement an Interface in Domain-Driven Design

六眼飞鱼酱① 提交于 2019-12-01 16:10:02
问题 I'm working on a project using both domain-driven design and test-driven development. While reading through the DDD book by Evans, I noticed that he did not define interfaces for aggregate roots in the domain. If I'm doing both DDD and TDD, should I define interfaces for each aggregate root to make the aggregate root classes easily testable and mockable? If so, should I also define interfaces for each entity contained within the aggregate root as well? From my searches on Google and

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

风流意气都作罢 提交于 2019-12-01 16:08:39
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 XXCircle was drawn."; s.DrawXXShape(); string actual = Console.ReadLine(); Assert.AreEqual(expected, actual);

Convenient method in GoogleTest for a double comparison of not equal?

折月煮酒 提交于 2019-12-01 16:04:59
I'm looking for something similar to the ASSERT_EQ / ASSERT_NE for ASSERT_DOUBLE_EQ. Maybe I'm missing an easy way of doing this without having a ASSERT_DOUBLE_NE? You can use the companion mocking framework Google Mock. It has a powerful library of matchers (a la Hamcrest), which you can use with the EXPECT_THAT/ASSERT_THAT macros: EXPECT_THAT(value, FloatEq(1)); EXPECT_THAT(another_value, Not(DoubleEq(3.14))); It looks like you're out of luck. However, you could add one yourself. I built the following code using ASSERT_DOUBLE_EQ and ASSERT_NE as a pattern. #define ASSERT_DOUBLE_NE(expected,

As a “mockist” TDD practitioner, should I mock other methods in the same class as the method under test?

点点圈 提交于 2019-12-01 15:57:14
After reading Martin Fowler's Mocks Aren't Stubs , I've discovered I've been practicing TDD in the "mockist" fashion. But I'm wondering if even in mockist TDD if one can take mocking too far. Here's an updated example in Python-style pseudo-code: def sync_path(self): if self.confirm_or_create_connection(): self.sync(self.dirpath) The confirm_or_create_connection() method creates a connection to a server. I tested a method similar to this in two tests, both of which mock confirm_or_create_connection() and sync() (even though they're both methods in the same class). In one test the mock confirm

Check several different example inputs in a single test?

孤街醉人 提交于 2019-12-01 15:38:56
Let's say I want to write a function that validates an email address with a regex. I write a little test to check my function and write the actual function. Make it pass. However, I can come up with a bunch of different ways to test the same function (test@test.com; test234@test.com; test.test.com, etc). Do I put all the incantations that I need to check in the same, single test with several ASSERTS or do I write a new test for every single thing I can think of? Thanks! Paul Alexander Most testing frameworks now support some sort of data based testing to let you run the same test on multiple

URI::InvalidURIError: bad URI(is not URI?) testing Rails controllers

吃可爱长大的小学妹 提交于 2019-12-01 15:20:28
I get URI::InvalidURIError testing Rails Home controller: require 'test_helper' class HomeControllerTest < ActionDispatch::IntegrationTest test "should get index" do get :index assert_response :success end end get the following error: E Error: HomeControllerTest#test_should_get_index: URI::InvalidURIError: bad URI(is not URI?): http://www.example.com:80index test/controllers/home_controller_test.rb:7:in `block in <class:HomeControllerTest>' The stack is the following: Rails 5.0.0.beta3 minitest (5.8.4) Controller tests inherit from ActionController::TestCase , while your test inherits from

How do unit tests change when a base class is driven out?

青春壹個敷衍的年華 提交于 2019-12-01 15:04:54
问题 This is in part a followup to this question. I'm not sure the best way to ask this, so I'll try a short story to set the scene: Once upon a time, there was a class ‘A’, which had a unit test class ‘ATests’ responsible for testing its behaviour through the public interface. They lived happily together for a while and then a change happened, and class ‘B’ came along, which as it turned out had a lot in common with class ‘A’, so a base class was introduced. The public behaviour of the base class

Testing Spyne application

我的未来我决定 提交于 2019-12-01 13:26:35
问题 What is the best practice to test Spyne application. Does it have test client like Django or Flask. I dont like idea to start wsgi server to test my application. Here is my flask+spyne example https://github.com/satyrius/flask-spyne-example 回答1: For testing, we have the NullServer : http://spyne.io/docs/2.10/reference/server.html?highlight=nullserver#spyne.server.null.NullServer It implements something close to the suds interface. Here's an example: >>> app = Application(...) >>> null =

“Code covered” vs. “Code tested”?

岁酱吖の 提交于 2019-12-01 11:14:51
Converting my current code project to TDD, I've noticed something. class Foo { public event EventHandler Test; public void SomeFunction() { //snip... Test(this, new EventArgs()); } } There are two dangers I can see when testing this code and relying on a code coverage tool to determine if you have enough tests. You should be testing if the Test event gets fired. Code coverage tools alone won't tell you if you forget this. I'll get to the other in a second. To this end, I added an event handler to my startup function so that it looked like this: Foo test; int eventCount; [Startup] public void

Assert to compare two lists of objects C#

柔情痞子 提交于 2019-12-01 10:30:15
I am currently trying to learn how to use unit testing, and I have created the actual list of 3 animal objects and the expected list of 3 animal objects. The question is how do I Assert to check the lists are equal? I have tried CollectionAssert.AreEqual and Assert.AreEqual but to no avail. Any help would be appreciated. The test method: [TestMethod] public void createAnimalsTest2() { animalHandler animalHandler = new animalHandler(); // arrange List<Animal> expected = new List<Animal>(); Animal dog = new Dog("",0); Animal cat = new Cat("",0); Animal mouse = new Mouse("",0); expected.Add(dog);