tdd

Why is design-by-contract not so popular compared to test-driven development?

狂风中的少年 提交于 2019-11-30 06:16:17
问题 You may think this question is like this question asked on StackOverflow earlier. But I am trying to look at things differently. In TDD, we write tests that include different conditions, criteria, verification code. If a class passes all these tests we are good to go. It is a way of making sure that the class actually does what it's supposed to do and nothing else. If you follow Bertrand Meyers ' book Object Oriented Software Construction word by word, the class itself has internal and

When to rewrite a code base from scratch

折月煮酒 提交于 2019-11-30 06:09:38
问题 I think back to Joel Spolsky's article about never rewriting code from scratch. To sum up his argument: The code doesn't get rusty, and while it may not look pretty after many maintenance releases, if it works, it works. The end user doesn't care how pretty the code is. You can read the article here: Things You Should Never Do I've recently taken over a project and after looking through their code, it's pretty awful. I immediately thought of prototypes I had built before, and explicitly

Moq - mock.Raise should raise event in tested unit without having a Setup

北慕城南 提交于 2019-11-30 05:43:04
I have a presenter class, that attaches an event of the injected view. Now I would like to test the presenter reacting on correctly on the event. This is the view interface IView: public interface IView { event EventHandler MyEvent; void UpdateView(string test); } This ist the view implementing IView public partial class MyView : IView { public event EventHandler MyEvent; public MyView() { this.combo.SelectedIndexChanged += this.OnSelectedIndexChanged; } public void UpdateView(string test) { this.textBox.Text = test; } private OnSelectedIndexChanged(Object sender, EventArgs e) { if (this

The Purpose of Mocking

和自甴很熟 提交于 2019-11-30 05:42:42
What is the purpose of mocking? I have been following some ASP.NET MVC tutorials that use NUnit for testing and Moq for mocking. I am a little unclear about the mocking part of it though. The purpose of mocking is to isolate the class being tested from other classes. This is helpful when a class : connects to an external resource (FileSystem, DB, network ... ) is expensive to setup, or not yet available (hardware being developed) slows down the execution of the unit tests has a non-deterministic behavior has (or is) a user interface It also makes it easier to test for error conditions, as your

How to deal with the test data in Junit?

我的未来我决定 提交于 2019-11-30 05:03:14
问题 In TDD(Test Driven Development) development process, how to deal with the test data? Assumption that a scenario, parse a log file to get the needed column. For a strong test, How do I prepare the test data? And is it properly for me locate such files to the test class files? 回答1: Maven, for example, uses a convention for folder structures that takes care of test data: src main java <-- java source files of main application resources <-- resource files for application (logger config, etc) test

How to exclude Projects with names ending in “.Test” from my code coverage analysis in VS2012 Unit Tests

主宰稳场 提交于 2019-11-30 04:28:57
My solution is set up with projects called "ProjectName" with "ProjectName".Tests containing my unit tests. I'd like to exclude the test projects from the code coverage analysis under VS 2012 (MS Test) and have successfully managed to do this by adding the ExcludeFromCodeCoverage attribute to each test class as described here . As the number of tests classes is growing it would be nice to exclude the entire Test assemblies. I want to use the .runsettings file also described in that MSDN link but don't seem to be having any luck. Here is my .runsettings file: <?xml version="1.0" encoding="utf-8

Unit testing private code [duplicate]

爷,独闯天下 提交于 2019-11-30 03:30:12
This question already has an answer here: Unit testing private methods in C# 11 answers I am currently involved in developing with C# - Here is some background: We implement MVP with our client application and we have a cyclomatic rule which states that no method should have a cyclomatic complexity greater than 5. This leads to a lot of small private methods which are generally responsible for one thing. My question is about unit testing a class: Testing the private implementation through the public methods is all fine... I don't have a problem implementing this. But... what about the

In F# how do you pass a collection to xUnit's InlineData attribute

霸气de小男生 提交于 2019-11-30 03:29:38
问题 I would like to be about to use a list, array, and/or seq as a parameter to xUnit's InlineData. In C# I can do this: using Xunit; //2.1.0 namespace CsTests { public class Tests { [Theory] [InlineData(new[] {1, 2})] public void GivenCollectionItMustPassItToTest(int[] coll) { Assert.Equal(coll, coll); } } } In F# I have this: namespace XunitTests module Tests = open Xunit //2.1.0 [<Theory>] [<InlineData(8)>] [<InlineData(42)>] let ``given a value it must give it to the test`` (value : int) =

What should a “unit” be when unit testing?

喜你入骨 提交于 2019-11-30 03:01:30
On Proggit today I was reading the comment thread on a submission entitled, " Why Unit Testing Is A Waste of Time ". I'm not really concerned with premise of the article so much as I am with a comment made concerning it: The stem of the problem is that most “units” of code in business software projects are trivial. Change the size of the unit until it is no longer trivial? Who the hell defined the unit of code as a single function or method anyway!? and Well, some of the guys I worked with wanted to define a unit as single functions. It was completely stupid. My favorite definition of "unit"

Android Studio + Robolectric + Gradle Class Not Found Exception

。_饼干妹妹 提交于 2019-11-30 02:46:14
问题 I downloaded Robolectric deckard-gradle project from https://github.com/robolectric/deckard-gradle and imported to Android Studio. On my first run i got !!! JUnit version 3.8 or later expected: java.lang.RuntimeException: Stub! at junit.runner.BaseTestRunner.<init>(BaseTestRunner.java:5) at junit.textui.TestRunner.<init>(TestRunner.java:54) at junit.textui.TestRunner.<init>(TestRunner.java:48) at junit.textui.TestRunner.<init>(TestRunner.java:41) Error and i fixed this from .iml. Then i got: