Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
It’s true that using Contracts.Requires and Contracts.Ensure in C# methods will reduce the necessary unit tests for that methods? Can I just ignore the range of values that are not in conformity with the contracts or those values should also be included in the unit tests?
It should not, design by contract is not intended to replace unit testing, or any kind of testing. Pre-conditions and post-conditions are used to enforce a contract, but the end client of that contract needs to make sure that such contract is still in place. So you need to keep the unit tests in place with all range of values to make sure everything is the way it should be.
Related
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
I am considering NPoco for a large business application. I am a bit concerned that is it worth to develop a repository pattern?
I will need to handle complex SQL statements and extensive database operations on several entities in a same use case.
NPoco provides a variety of db operations functions, which I think will not be (directly) exposed to the consumer layer(s) by my repository layer.
Edit-1
Which approach is better to get most out of NPoco?
If you want to invest time in unit tests, then the Repository Pattern is worth it. However if most of your application logic is in stored procs and functions, then you will be limited with unit tests and just spend your time in integration testing.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
The project I work on has multiple layers and each layer's object is being used in the subsequent layer. But some of the classes do not have any interfaces and have non virtual methods. So basically I will not be able to use a mock framework to stud those classes from other layers. When I asked the developer to create an interface for the same class, so that I can mock it, he asked me why should I create an interface if I am not going to reuse it.
Is it a good practice to write interface just to improve the testability of the code?
Your code should be loosely coupled and has good dependency management to allow you write unit-tests easily. If you can't write unit-tests easily, it's the first sign that your code is not well-architectured enough, and you need to refactor it. So, your motivation to change production code(in your case to add Interface) should be to make your code better, not just to aid testing. If you could do the first - you would get the second for free.
Btw, one of the main benefits of following the TDD practice is that the good architecture is enforced from the beginning: it's difficult to write untestable code, because you write tests before you write code.
So, the answer is YES, it's OK to add Interface, but it should be done for the sake of good architecture, not just to help you write tests for bad architecture.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I am working with several developers who develop .net components for me.
I manage the licensing mechanism and want to hide the implementation.
I would like to just provide them the interface, with for example the methodIsLicenseValid() so they must use it in the code but cannot access the implementation.
Which pattern or technology should I use to reach that objective?
You should be using a Web Service to expose the methodIsLicenseValid(), and let your devs invoke it whenever necessary.
This will be suitable for your production environment anyways and also will allow you to change the implementation of the methodIsLicenseValid(), without causing hasles to the devs, as opposed to providing a library/dll to them
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I have planned to implement automated testing for our web application .I want the tool to be open source, test cases should be written in C sharp.
So i choose to use selenium Web-driver and N-unit. I have a set of questions.
Can i only unit testing with this setup? Cannot do function testing?
I'll avoid answering your first question as it's not suited for StackOverflow :)
Can i only unit testing with this setup? Cannot do function testing?
You can use Selenium with a wide range of tasks.
I started off doing unit testing of individual components of our web application.
Then I moved on to functionally testing the end-to-end behavior.
Currently I'm doing massive stress testing with hundreds of concurrent browser sessions.
All using Selenium.
Should i have to write all test cases as methods?
As far as I know (and I don't know a lot), the most flexibility is attained when you conceptualize your testing architecture this way.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
In theory, it is difficult to perform tests on functional code bases that need interactions with database, but I think we can use mocks. In real life applications, do you have failed cases when applying mocks to perform TDD tests with databases ? Could you shared some thoughts to explain this to me?
In tdd i use mocks to replace the physical database access with a fake (mock).
For databaseaccess i am always using a The Repository Pattern as api which can be easily mocked.
To Answer your question:
> do you have failed cases when applying mocks
> to perform TDD tests with databases ?
No as long all database-operations are encapsulated in the repository.