tdd

What is the expected syntax for checking exception messages in MiniTest's assert_raises/must_raise?

天涯浪子 提交于 2019-11-30 02:32:45
What is the expected syntax for checking exception messages in MiniTest's assert_raises / must_raise ? I'm trying to make an assertion something like the following, where "Foo" is the expected error message: proc { bar.do_it }.must_raise RuntimeError.new("Foo") You can use the assert_raises assertion, or the must_raise expectation. it "must raise" do assert_raises RuntimeError do bar.do_it end -> { bar.do_it }.must_raise RuntimeError lambda { bar.do_it }.must_raise RuntimeError proc { bar.do_it }.must_raise RuntimeError end If you need to test something on the error object, you can get it from

AutoMockContainer with support for automocking classes with non-interface dependencies

瘦欲@ 提交于 2019-11-30 02:25:08
I have a constructor which has a non-interface dependency: public MainWindowViewModel(IWorkItemProvider workItemProvider, WeekNavigatorViewModel weekNavigator) I am using the Moq.Contrib automockcontainer. If I try to automock the MainWindowViewModel class, I get an error due to the WeekNavigatorViewModel dependency. Are there any automocking containers which supports mocking of non-interface types? As Mark has shown below; yes you can! :-) I replaced the Moq.Contrib AutoMockContainer with the stuff Mark presents in his answer, the only difference is that the auto-generated mocks are

How do you test code written against AWS API [closed]

馋奶兔 提交于 2019-11-30 02:23:13
I'm writing an application in Java that will upload a file up to AWS S3. The file will be given to the application in an argument, not hardcoded. I'd like to write tests to ensure that the file actually gets uploaded to S3. The test will be written before the code for TDD. (I have actually already written the code, but I'd like to ingrain TDD practices into all of my work as a habit) How exactly would I go about doing this? I will be using JUnit as that's what I'm most familiar with. Thanks in advance for any help. Op De Cirkel The actual uploading and the tests that are doing it are part of

How do I convince programmers in my team to do TDD? [closed]

陌路散爱 提交于 2019-11-30 02:05:59
I am aware of this question: https://stackoverflow.com/questions/428691/how-to-encourage-implementation-of-tdd In my team, we write a lot of unit tests. But, in general the programmers tend to write unit tests after wrting the code. So, we first finish the module functionality and then write tests. Our coverage is around 70% for most modules. I have tried convincing my technical manager and my team members to do pure TDD wherein we first write tests and then the code, but invain. I think writing tests first allows us to discover design better. Am I just being finicky, especially when our

Unit testing a class with no return value?

可紊 提交于 2019-11-30 01:41:33
I didn't find much in tutorials on this specific question.. So I have a class called 'Job' which has public ctors and a single public Run() function. Everything in the class is private and encapsulated in the class. (You may remember an older post here on this Testing only the public method on a mid sized class? , which replies helped me greatly) This Run() method does a bunch of things - takes an excel file as input, extracts data out of it, sends a request to a third party data vendor, takes the result and puts it in the database and logs the begining / end of the job. This Job class uses 3

Prefixing interfaces with I?

限于喜欢 提交于 2019-11-30 01:36:26
I am currently reading "Clean Code" By Rober Martin (UncleBob), and generally loving the musings of UncleBob. However, I got a bit confused, when I read that he avoids prefixing interfaces like "IPerson". He states "I don't want my users knowing that I'm handing them an interface". Thinking in TDD/injection perspective, I will always be very interested in telling the "users" of my classes that I am handing on an interface. The primary reason is that I consider Interfaces contracts between the different "agents" of a system. An agent working with one corner of my system, should not know the

How to detect if a mocha test is running in node.js?

独自空忆成欢 提交于 2019-11-30 01:14:52
问题 I want to make sure that in case the code is running in test mode, that it does not (accidentally) access the wrong database. What is the best way to detect if the code is currently running in test mode? 回答1: As already mentioned in comment it is bad practice to build your code aware of tests. I even can't find mentioned topic on SO and even outside. However, I can think of ways to detect the fact of being launched in test. For me mocha doesn't add itself to global scope, but adds global.it .

Verify value of reference parameter with Moq

南楼画角 提交于 2019-11-30 00:44:54
问题 I just switched to Moq and have run into a problem. I'm testing a method that creates a new instance of a business object, sets the properties of the object from user input values and calls a method (SaveCustomerContact ) to save the new object. The business object is passed as a ref argument because it goes through a remoting layer. I need to test that the object being passed to SaveCustomerContact has all of its properties set as expected, but because it is instantiated as new in the

problem with rspec test, undefined method 'post'

僤鯓⒐⒋嵵緔 提交于 2019-11-30 00:23:53
问题 I am writing a spec to test the behavior of the mashup_controller when someone sends a query through a URL. I need to simulate the parameters contained in the URL, and i read that the post() method will do that, however when i get an error: 1) MashupController simulates query Failure/Error: post :create NoMethodError: undefined method `post' for #<RSpec::Core::ExampleGroup::Nested_1:0x980bc50> # ./mashup_controller_rspec.rb:9:in `block (2 levels) in <top (required)>' Finished in 0.20199

Is 100% code coverage a really good thing when doing unit tests? [closed]

邮差的信 提交于 2019-11-29 23:59:11
I always learned that doing maximum code coverage with unit tests is good . I also hear developers from big companies such as Microsoft saying that they write more lines of testing code than the executable code itself. Now, is it really great? Doesn't it seem sometimes like a complete loss of time which has an only effect to making maintenance more difficult ? For example, let's say I have a method DisplayBooks() which populates a list of books from a database. The product requirements tell that if there are more than one hundred books in the store, only one hundred must be displayed . So,