How I can unit test Dapper Extension Method?

What's the best way (i.e. standard practice) to implement unit testing in my code?

  • If I'm designing a program in, let's say Java, how do I include the ability to unit test? If I have a method, like: public int add(int a, int b) { return a + b; } ...do I just need a separate Class (i.e. UnitTest.java) that calls that method and checks that the response is 3 when I input a=1 and b=2? Essentially I'm wondering if I actually need to do all of this manually, or if there's a simpler way to find the source of LOGICAL errors in my code (as opposed to syntax and other errors like NullPointerException, etc).

  • Answer:

    How it is usually done, you have not only separate Class, but separate project, where you have all your test classes. If you want to be strict and go with test first approach, you should start with test first, so you would write something like public void addTest() {      .....//class constructor and so on       int expectedResult = 2;       int actualResult = class.add(1,1);       assertEquals(expectedResult,actualResult); } If you want to do this properly, you should see the test fail first, if you want to learn more, watch this step by step and you will see how the flow works.

Filip Tuhy at Quora Visit the source

Was this solution helpful to you?

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.