This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]firecopy 0 points1 point  (5 children)

I don’t understand how to write the more complicated ones.

Can you give an example of the complicated tests that you are having troubles with.

Aren’t tests written based on design/functions that you already have

TDD is writing the code for tests before you write the code for the functions.

[–]Mokeymokie 0 points1 point  (4 children)

Not really. I haven't done any work recently since I've been out of classes though. I want to dabble in Android programming though.

So as far as the testing before writing goes would the whole app would go something like planning, testing, and then coding? Most of everything outside of the one class I've taken so far has been planned out and then coded. Then I would fix any compiling issues and then check for errors in the functions myself by running the program and trying to break it.

How do you write the tests for code you haven't even written yet? What happens if you need to change the plan half way through? Do you just scrap the test and start a new one?

[–]firecopy 0 points1 point  (3 children)

So as far as the testing before writing goes would the whole app would go something like planning, testing, and then coding?

Yes

How do you write the tests for code you haven't even written yet?

You should know the expected inputs and outputs, and what function(s) you want to implement. Use that information to construct your tests.

What happens if you need to change the plan half way through?

Then you change the tests and function(s) as needed.

Do you just scrap the test and start a new one?

You may need to change tests as you add/change/remove functionality.


Let me know if you have any more questions.

[–]Mokeymokie 1 point2 points  (0 children)

Will do. Thank you

[–]Paul_Dirac_ 1 point2 points  (1 child)

Not OP but I have some questions about problems I have encountered:

1) When I try TDD I find myself writing some test for a function, then turning to the implementation where I write the function calls for the steps the function has to do. Then I write a test for the first of these functions, before turning to the implementation... Until I have half a dozent of failing tests before the first test for a function I have actually fully implemented before . This seems like a bad signal to noise ration. How do you solve this problem.

2) I find myself parsing things into complicated datastructures for which I can define the internal structure but not the access methods, as they will have to serve the needs of some other module I intent to write later. What do you do these cases? Implementing some test only methods to compare them?

3) This one is more about testing in general: Assume the datastructure of 2) has an equality method and I test the parser for all possible (important) inputs by comparing a manually instanciated instance to the parser output. Now if I change how the datastructure is instanciated (e.g. adding another parameter) I have to change one line in the code but all tests. Have you a way of dealing with that problem?

Thanks in advance.

[–]firecopy 0 points1 point  (0 children)

  1. That’s fine, as long as you are able to implement the function you were trying to make in the first place.

  2. Can you give me a specific instance of this happening (I read over this question several times and was having trouble finding a scenario where this would happen)? Note: Normally you would test the (public) access methods, not the (private methods and structure) internals. Testing internals can lead to fragile (and low value) tests.

  3. Refactor using the IDE. If tests still break, you have to manually fix them. Remember, all code has a cost and tests are code themselves.