none
Unit tests - startup RRS feed

  • Question

  • Hello!

    Does anyone know a good example, tutorial for unit tests?

    • How do you create one?
    • What advantages and disadvantages do I have?

    I spoke to my boss, he said, then a project takes even longer?

    If the test was successful for me, not for the customer, how can I test where the cause lies?

    // ------

    Example: server client, question answer. The test is in my project. When installing on a customer PC I do not have the test server, but the Orignal PC and server from the customer.

    How I do you test this together? Are there any guidelines?

    I found this. introduction-of-unit-test

    Thanks for tipps in advance.

    Best regards Markus

    Sunday, November 17, 2019 11:27 AM

Answers

  • I spoke to my boss, he said, then a project takes even longer?

    Well, not exactly. The first cut of the project will take longer. But once you tally the full life cycle of the project, including bug-fixing and new version updates, the total amount of time spent will be less with the unit tests than without them, if they are properly done.
    If the test was successful for me, not for the customer

    Ah, no. You are mixing things here. You are thinking about integration tests or acceptance tests. The unit tests cannot be executed for the customer. They run locally on your source code and they can only execute at development time. They cannot have any external dependencies (that's why we use dependency injection when we write the unit tests), so they cannot depend on anything that changes between your development environment and the customer's environment. If they do, then they are integration tests, not unit tests.

    Sunday, November 17, 2019 11:42 AM
  • How do you create one?

    https://www.pluralsight.com/guides/software-delivery-using-test-driven-development-tdd

    What advantages and disadvantages do I have?

    Cleaner and more bug free code. The flip-side is a developer writes bad/bogus test, becuase he or she doesn't have TDD and unit test fundamentals on how to do them.

    I spoke to my boss, he said, then a project takes even longer?

    Your boss doesn't understand the basics of why TDD is an important factor in the software development cycle. TDD is an initiative and a mandate in many organizations,  and the developer must go through the training. I think I have about 40 hours of mandated TDD training.  

    TDD may take longer time in the overall initial development cycle, but it will reduce the coding cost and development time in the long run in clean and bug free code in the project's life cycle. I cannot tell you the times that a unit test has exposed a bug in coding logic.

    If the test was successful for me, not for the customer, how can I test where the cause lies?

    You would have to implement integration testing in the client's environment. 

    The tutorial on UT you posted is woefully inadequate, becuase there other factors that come into play in writing a good UT,  like there are books on the subject. 

    https://www.artima.com/weblogs/viewpost.jsp?thread=126923

    https://blog.cleancoder.com/uncle-bob/2014/12/17/TheCyclesOfTDD.html

    Sunday, November 17, 2019 12:52 PM
  • Hello

    • There are tons of tutorials on creating unit test. Start out with basic tutorials and as you progress you will learn about using base classes, initialization and cleanup, mocking or in some cases like Entity Framework Core testing with in memory testing. 
    • As stated already you are mixing up unit testing with acceptance testing. 
    • Advantages, many including verifying your code works as expected, find issues with business logic, find code logic issues etc.
    • Disadvantages, mainly the time to produce a product take longer while the counter to this is a much more solid product.

    Before even beginning to write unit test I advise you to learn Gherkin syntax which will provide a path for writing your unit test.

    As you advance TDD (Test Driven Development) which Visual Studio is very capable of creating classes and such as your work.


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Sunday, November 17, 2019 1:05 PM
  • Hello Karen,

    >There are tons of tutorials on creating unit test. Start out with basic tutorials
    >and as you progress you will learn about using base classes, initialization
    >
    and cleanup, mocking or in some cases like Entity Framework Core
    >
    testing with in memory testing.

    Tutorials Unit Tests

    Of course,
    yes sure there are many hits if you take google. Can you recommend any?
                    
    Greetings Markus



    I don't have time to provided a well thought out list.

    What I will say is no one site will have all the answers.  There are a lot of online lessons at pluralsight on unit testing but that is a paid for service and well worth the $$$'s if your company can spring for the cost. You can for instance start a course on one device and pickup on another device, takes notes, download source code and more.

    For a glimpse into some simple to intermediate unit testing see my TechNet article and source code on GitHub. 

    The following shows some ideas for unit testing Entity Framework Core (I've not fully completed it yet but all that is there works)


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    • Marked as answer by Markus Freitag Tuesday, November 19, 2019 7:49 AM
    Monday, November 18, 2019 7:49 PM

All replies

  • I spoke to my boss, he said, then a project takes even longer?

    Well, not exactly. The first cut of the project will take longer. But once you tally the full life cycle of the project, including bug-fixing and new version updates, the total amount of time spent will be less with the unit tests than without them, if they are properly done.
    If the test was successful for me, not for the customer

    Ah, no. You are mixing things here. You are thinking about integration tests or acceptance tests. The unit tests cannot be executed for the customer. They run locally on your source code and they can only execute at development time. They cannot have any external dependencies (that's why we use dependency injection when we write the unit tests), so they cannot depend on anything that changes between your development environment and the customer's environment. If they do, then they are integration tests, not unit tests.

    Sunday, November 17, 2019 11:42 AM
  • How do you create one?

    https://www.pluralsight.com/guides/software-delivery-using-test-driven-development-tdd

    What advantages and disadvantages do I have?

    Cleaner and more bug free code. The flip-side is a developer writes bad/bogus test, becuase he or she doesn't have TDD and unit test fundamentals on how to do them.

    I spoke to my boss, he said, then a project takes even longer?

    Your boss doesn't understand the basics of why TDD is an important factor in the software development cycle. TDD is an initiative and a mandate in many organizations,  and the developer must go through the training. I think I have about 40 hours of mandated TDD training.  

    TDD may take longer time in the overall initial development cycle, but it will reduce the coding cost and development time in the long run in clean and bug free code in the project's life cycle. I cannot tell you the times that a unit test has exposed a bug in coding logic.

    If the test was successful for me, not for the customer, how can I test where the cause lies?

    You would have to implement integration testing in the client's environment. 

    The tutorial on UT you posted is woefully inadequate, becuase there other factors that come into play in writing a good UT,  like there are books on the subject. 

    https://www.artima.com/weblogs/viewpost.jsp?thread=126923

    https://blog.cleancoder.com/uncle-bob/2014/12/17/TheCyclesOfTDD.html

    Sunday, November 17, 2019 12:52 PM
  • Hello

    • There are tons of tutorials on creating unit test. Start out with basic tutorials and as you progress you will learn about using base classes, initialization and cleanup, mocking or in some cases like Entity Framework Core testing with in memory testing. 
    • As stated already you are mixing up unit testing with acceptance testing. 
    • Advantages, many including verifying your code works as expected, find issues with business logic, find code logic issues etc.
    • Disadvantages, mainly the time to produce a product take longer while the counter to this is a much more solid product.

    Before even beginning to write unit test I advise you to learn Gherkin syntax which will provide a path for writing your unit test.

    As you advance TDD (Test Driven Development) which Visual Studio is very capable of creating classes and such as your work.


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Sunday, November 17, 2019 1:05 PM
  • Hello Karen,

    >There are tons of tutorials on creating unit test. Start out with basic tutorials
    >and as you progress you will learn about using base classes, initialization
    >
    and cleanup, mocking or in some cases like Entity Framework Core
    >
    testing with in memory testing.

    Tutorials Unit Tests

    Of course,
    yes sure there are many hits if you take google. Can you recommend any?
                    
    Greetings Markus



    Monday, November 18, 2019 5:36 PM
  • Hello Karen,

    >There are tons of tutorials on creating unit test. Start out with basic tutorials
    >and as you progress you will learn about using base classes, initialization
    >
    and cleanup, mocking or in some cases like Entity Framework Core
    >
    testing with in memory testing.

    Tutorials Unit Tests

    Of course,
    yes sure there are many hits if you take google. Can you recommend any?
                    
    Greetings Markus



    I don't have time to provided a well thought out list.

    What I will say is no one site will have all the answers.  There are a lot of online lessons at pluralsight on unit testing but that is a paid for service and well worth the $$$'s if your company can spring for the cost. You can for instance start a course on one device and pickup on another device, takes notes, download source code and more.

    For a glimpse into some simple to intermediate unit testing see my TechNet article and source code on GitHub. 

    The following shows some ideas for unit testing Entity Framework Core (I've not fully completed it yet but all that is there works)


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    • Marked as answer by Markus Freitag Tuesday, November 19, 2019 7:49 AM
    Monday, November 18, 2019 7:49 PM