tdd

Rails fixtures — how do you set foreign keys?

安稳与你 提交于 2019-12-18 03:49:09
问题 I'm reading about Rails fixtures in this guide (thanks, trevorturk). It appears you define classes in a Yaml file and they're automatically loaded into the test DB -- cool. But if you want to specify that this recipe belongs to that cookbook (or whatever) how do you do that? Are you supposed to specify the values for cookbook.id and recipe.cookbook_id by hand in the Yaml code? (Just a guess -- the guide doesn't show anything like that.) Or is there a more suitable way? 回答1: You should use

How to unit test private methods in BDD / TDD?

穿精又带淫゛_ 提交于 2019-12-18 03:12:15
问题 I am trying to program according to Behavior Driven Development, which states that no line of code should be written without writing failing unit test first. My question is, how to use BDD with private methods? How can I unit test private methods? Is there better solution than: - making private methods public first and then making them private when I write public method that uses those private methods; or - in C# making all private methods internal and using InternalsVisibleTo attribute. 回答1:

How to unit test private methods in BDD / TDD?

烂漫一生 提交于 2019-12-18 03:12:15
问题 I am trying to program according to Behavior Driven Development, which states that no line of code should be written without writing failing unit test first. My question is, how to use BDD with private methods? How can I unit test private methods? Is there better solution than: - making private methods public first and then making them private when I write public method that uses those private methods; or - in C# making all private methods internal and using InternalsVisibleTo attribute. 回答1:

TDD and Mocking out TcpClient

回眸只為那壹抹淺笑 提交于 2019-12-17 22:52:43
问题 How do people approach mocking out TcpClient (or things like TcpClient)? I have a service that takes in a TcpClient. Should I wrap that in something else more mockable? How should I approach this? 回答1: When coming to mock classes that are not test friendly (i.e. sealed/not implementing any interface/methods are not virtual), you would probably want to use the Adapter design pattern. In this pattern you add a wrapping class that implements an interface. You should then mock the interface, and

Test Driven Design for iPhone Native apps

限于喜欢 提交于 2019-12-17 22:35:33
问题 I'm experimenting with the iPhone SDK and doing some TDD ala Dr. Nic's rbiPhoneTest project. I'm wondering how many, if any, have been successful using this or any other testing framework for iPhone/Cocoa? More important, I'd like to know how to best assert a proprietary binary request/response protocol. The idea is to send a binary request over the network and receive a binary response. Requests and responses are created using byte and'ing and or'ing. I'm using the golden copy pattern to

Django: test failing on a view with @login_required

隐身守侯 提交于 2019-12-17 22:25:58
问题 I'm trying to build a test for a view that's decorated with @login_required, since I failed to make it work, I did a simple test and still can't make it pass. Here is the code for the simple test and the view: def test_login(self): user = self._create_new_user() self.assertTrue(user.is_active) login = self.client.login(username=user.username, password=self.data['password1']) self.failUnless(login, 'Could not log in') response = self.client.get('/accounts/testlogin/') self.assertEqual(response

TDD and BDD Differences

梦想与她 提交于 2019-12-17 21:41:05
问题 I honestly don't see the difference between BDD and TDD. I mean, both are just tests if what is expected happens. I've seen BDD Tests that are so fleshed out they practically count as TDD tests, and I've seen TDD tests that are so vague that they black box a lot of code. Let's just say I'm pretty convinced that having both is better. Here's a fun question though. Where do I start? Do I start out with high level BDD tests? Do I start out with low level TDD tests? 回答1: I honestly don't see the

Spring Boot integration test ignoring secure=false in AutoConfigureMockMvc annotation, get 401

时光总嘲笑我的痴心妄想 提交于 2019-12-17 20:13:39
问题 Can't make my @SpringBootTest work. It says authentication is on, which I do not want. I've set it up with @AutoConfigureMockMvc(secure = false) I submit a mock request with some JSON and my integration test should test the whole stack, taking it through the web layer with SDR to JPA and then into the in-memory database, so I can test for it using JdbcTemplate . But the response is 401 , requires authentication. Why isn't the @AutoConfigureMockMvc(secure = false) enough? What's missing?

testing an internal class

社会主义新天地 提交于 2019-12-17 19:47:13
问题 how to write unit tests to internal classes ??? 回答1: You write tests which specify the behaviour of the top-level class' external interface. Whether that class uses internal classes to implement that behaviour or not, is an implementation detail of the class, and the tests don't need to know anything about it. If the internal class cannot be adequately tested through the top-level class' interface, then it's usually best to move the internal class out and test it directly as a new top-level

Let method take any data type in c#

给你一囗甜甜゛ 提交于 2019-12-17 17:44:24
问题 I have a lot of unit tests that pretty much tests the same behavior. However, data type changes. I am trying to create a generic method that can take any data type. I tried making my input parameter var but that's not allowed. Also, looked into c# generics but that usually deals with a list. 回答1: You could make the parameter an object : public void DoSomething(object arg) { //... Or you could do what I prefer and make a generic method: public void DoSomething<T>(T arg) { //... The generic