TDD application when the application is 100% CRUD

I regularly encounter this problem, and I'm not sure how to overcome this obstacle. I really want to start learning and apply Test-Driven-Development (or BDD, or something else), but it looks like every application I make where I want to apply is pretty much just a standard CRUD database, and I'm not sure how to apply it. Objects to a large extent do nothing except that they are stored in a database; there is no complicated logic that needs to be verified. There is a gateway that I will eventually need to test for a third-party service, but I want to create the application core first.

Whenever I try to write tests, I end up testing the basic materials, which I probably shouldn't test in the first place (like getters / seters), but this doesn't look like the objects have anything else. I guess I could check the perseverance, but it never seems right to me, because you shouldn't actually click on the database, but if you scoff at it, you really don't test anything, because you control the data that spits back; for example, I saw many examples where there is a repository layout that mimics the database by cycling and creating a list of known values, and the test verifies that the "repository" can drop a certain value ... I am not seeing the point of such a test, because of course , the "repository" is about to return this value; it is hardcoded in class! Well, I see this from a pure TDD point of view (i.e. you need to have a test saying that your repository needs a GetCustomerByName method or something else before you can write the method itself), but this seems like the following dogma without for any reason other than its "path" - the test does not seem to do anything useful except to justify the method.

Am I thinking about it wrong?

For example, launch the mill contact management application. We have contacts and we can say that we can send messages to contacts. Therefore, we have two objects: Contact and Message , each of which has common properties (for example, first name, last name, email address for the contact and subject and body, and date for the message). If none of these objects have any real behavior or should not execute any logic, then how do you use TDD when developing an application like this? The only purpose of the application is to basically pull out the list of contacts and display them on the page, display a form for sending a message, etc. I don’t see any useful tests here - I might think of some tests, but they would be more of a test in order to say "Look, I have tests!" instead of actually testing some kind of logic (although Ruby on Rails makes good use of it, I don’t think checking validation is a “useful” test because it should be something that the framework takes care of for you)

+41
tdd
May 09 '09 at 1:39 a.m.
source share
9 answers

"The sole purpose of the application is to basically pull out the contact list."

Good. Check this. What does pull mean? It sounds like "logic."

"display them on page"

Good. Check this. Correctly displayed? What is there?

"display the form for sending a message"

Good. Check this. Are the fields correct? Do all input validations work?

"etc."

Good. Check this. Are requests being met? Find the right data? Display the correct data? Check input? Generate correct error messages for invalid inputs?

+14
May 09 '09 at 2:08 a.m.
source share

I am currently working on a pure CRUD application. But I see many advantages of Unit test cases (note - I did not say TDD)

I write the code first, and then the test cases, but not too fragmented, although

And I check CRUD operations - database persistence.

When I’ve finished saving - and moving on to the user interface layer, I will have enough confidence that my service level / persistence is good, and then I can focus on the user interface at the moment.

So, IMHO - there is always the advantage of testing TDD \ Unit (no matter how you call it, depending on how extreme you feel it) - even for a CRUD application you just need to find the right strategy for your application

Just use common sense .... and everything will be fine.

+5
May 09 '09 at 2:26 a.m.
source share

I feel like we are confusing TDD with Unit Testing.

Unit tests are special tests that test units of behavior. These tests are often included in the integration assembly. S.Lott described some excellent candidates only for those types of tests.

TDD is for design. More often than not, my tests that I write when using TDD will either be dropped or converted to Unit Test. The reason is that when I do TDD, I test my project while I develop my application, class, method, domain, etc.

In response to your scenario, I agree with what S.Lott meant, so what you need is a Unit test suite to test certain types of behavior in your application.

+4
May 13, '09 at 23:53
source share

Skip it. Everything will be fine. I am sure you have a deadline for meeting. (/Sarcasm)

Next month, we can come back and optimize requests based on user feedback. And break things that we did not know that we should not break.

If you think the project will last 2 weeks and then never be reopened, automatic testing is probably a waste of time. Otherwise, if you have an interest in “owning” this code for several months and having it active, perform some tests. Use your opinion about where the most dangerous. Worse, if you plan to be with the company for several years, and you have other teammates who replace each other on different parts of the system, and this may be your turn again in a year, to build several tests.

Do not redo this, but do "insert a few pins" into it so that if something starts to "move" you have some worries to draw attention to things.

Most of my testing is tests like JUnit or batch type diff, as well as a rudimentary screen-type scraper tool that I wrote a few years ago (a script with some regex + wget / curl type types). I heard that Selenium should be a good tool for testing the user interface of web applications, but have not tried it. Does anyone have available tools for local GUI applications ???

+3
May 9 '09 at 7:13
source share

TDDing is a simple CRUD application, in my opinion, similar to practicing guitar exercises - you might think that it’s boring and tiring, just to find out how much your game is improving. In development timelines - you are likely to write code that is less connected - more verifiable. In addition, you will most likely see things from the point of view of the consumer of the code - you will really use it. This can have many interesting side effects, such as more intuitive APIs, better separation of concerns, etc. It’s assumed that scaffold generators can do basic CRUD for you, and they have a place, especially for prototyping, but they are usually structured. Why not focus on the key domain in the first place, deferring the Framework / UI / Database solutions until you have a better idea of ​​the basic functionality - TDD will also help you with this. In your example: do you want messages to be a queue or hierarchical tree, etc.? Do you want to be downloaded in real time? How about sorting / searching? do you need to support JSON or just html? it is much easier to see these issues with BDD / TDD. If you are doing TDD, you can test your core logic without even using the framework (and wait a minute to load or run)

+3
Jan 26 '13 at 8:32
source share

Just an idea ...

Take CRUD requirements, use tools like watij or watir or AutoIt to create test cases. Start creating a user interface for passing test cases. After you set the UI and miss, perhaps only one test, start writing the logic level for this test, and then the db layer.

For most users, the user interface is a system. Remember to write test cases for each new layer you build. Therefore, instead of starting from db to app to the ui level, start in the opposite direction.

At the end of the day, you will likely have an accumulated powerful set of regression tests to give you some confidence in making refactoring safe.

This is just an idea ...

+2
May 09 '09 at 6:00 a.m.
source share

I understand what you are saying, but in the end your models will become quite advanced, which will require (or will be greatly enhanced) automated testing. If not, what you are essentially developing is a table that someone has already developed for you.

Since you mentioned Rails, I would say that running the standard create / read / update / delete test is a good idea for each property, especially because your test has to take into account permissions (which I think is huge). It also ensures that your migrations work the way you expected them to.

+1
May 09 '09 at 2:16 a.m.
source share

I am currently working on a CRUD application. What I am doing at this stage is to write unit tests for my repository objects and verify that the CRUD functions are working as they should. I found that at its core the module also tested the actual database code. Thus, we found a lot of errors in the database code. Therefore, I suggest that you move forward and continue to work with unit tests. I know that using TDD in CRUD applications is not as glamorous as what you could read in blogs or magazines, but it serves its purpose and you will be much better when you work on a more complex application.

+1
May 09 '09 at 2:52
source share

Nowadays, you don’t need to write much code for the CRUD application, except for the user interface, since there are 101 frameworks that will generate a database and a data access code.

So, I would look at reducing the amount of hand-written code and automating user interface testing. Then I will use the TDD of the odd bits of logic that need to be written manually.

+1
Mar 25 '11 at 12:16
source share



All Articles