c# - How can I unit test my project, when most of it access a database with a poor schema that I cannot change? -
I am working on an asp.net webform project.
Not included in this project, in addition to some tests, besides some unit tests, I wrote myself to cover a small static method. I would like to write unit test for the entire project so that I have a refactor Can I add code more efficiently to this project (I have support of CTO about this), but I have participated in a problem.
Most of the databases in the web application contain Linux queries, there is no intangibility between the database and the code, in other words we do not do anything like a repository, instead we only have linq queries Let us type them where we need them.
In my opinion, the unit test should not call the database directly because it will slow down, so I want to decouple them from the database. I first tried that I used to work with a MOQ framework, which is called MOQ, but then I read that LINQ-queries are a different behavior for LINQ-queries for the database, so that Consuming tests does not mean that I work from my methods
This allows me to hide Linux questions in repository classes, after considering the repository pattern, and then in my tests Not made duplicate these classes.
- Changing this project is a big thing to use in the repository pattern, and I'm not sure that the repository pattern is the right tool, so I would like to know in advance that it is appropriate or not.
- The database schema is not very good, it was created for us by another company, and they took only one general schema and some of us "customize it" in rows tables and columns in some tables There are many bad names, it can not contain all the data that we need it, and the logical structure is not very well suited for us, for which complex questions Require s. I am pretty sure that the correct solution is to write schema again to suit us, but CTO wants that it remains the same so that the project can be easily modified by the company, which created the database and project, if we want to , So there is no such option.
Considering that a repository pattern should be used, my question is how do I deal with a bad database schema? I think I need to hide it behind an abstract which handles complex clearing for me, perhaps to figure out how to look at the schema that schema should look like, but I can get it wrong, and I can tell about the details. Not sure in.
If you can give me examples and tutorials links, then I will be happy and tell me that my assumptions are wrong.
Thank you in advance for your patience and support. / P>
If this was me I would not focus on unit tests for this. I will first get a suite of end-to-end tests that mark the behavior of the system as it stands, as you restructure some parts of the system, there is some assurance that things get worse now Not that they were before.
As you say, different leak providers have different behaviors, that you are actually testing system tasks.
I can recommend SpecFlow as a great tool for building my behavior-based tests, and for a great overview of SpecFlow and why do you
Reading and reading links will get a lot more and comments can also be useful.
> You will see that the comments related to some comments given above require you to write unit tests, but you can often require refactors before writing tests * because the code is currently not testable ), But that it 'safe' T22 Catch without unit testing. By writing an end-to-end test, you can get out of this catch-22 at the expense of slow running test suits.
Comments
Post a Comment