Skip to main content
added 27 characters in body
Source Link
demouser123
  • 3.5k
  • 5
  • 29
  • 41

how How high level should be my unit-test?

I have a program with many classes. I manage the DI with Guice, btw.

I wanted to write in-progress tests to my code (unit tests and higher level).

I have few questions\difficulties:

  1. How high should my tests be?

    How high should my tests be?

    I know there is no "right\wrong" answer.

    I know there is no "right\wrong" answer. If I write the test too high it might be difficult for me to simulate all test cases.

    If I write the test too high it might be difficult for me to simulate all test cases.

    If I write the tests too low, every class\structural re-factoring I'll do will break the tests and that would be very tedious to maintain.

    I guess the solution is combining both? Or is there any best-practice guideline?

  2. How would you call tests that call the highest API of my code, when I use mocks only for out-of-process services (DB, Http service etc)? They are not unit-tests because I don't mock all dependencies?

  3. What is the best practice to inject mock using Guice in PROD code? create a mainModule class for each test-class? but then if I want a different data from the mock for each test - then I'll have as many mainModule classes as many test cases?

If I write the tests too low, every class\structural refactoring I'll do will break the tests and that would be very tedious to maintain.

I guess the solution is combining both? Or is there any best-practice guideline?

  1. How would you call tests that call the highest API of my code, when I use mocks only for out-of-process services (DB, Http service etc)? They are not unit-tests because I don't mock all dependencies?

  2. What is the best practice to inject mock using Guice in PROD code? create a mainModule class for each test-class? but then if I want a different data from the mock for each test - then I'll have as many mainModule classes as many test cases?

I could add a concrete example, but I thought the qquestion might be cleared in general. No?

how high level should be my unit-test?

I have a program with many classes. I manage the DI with Guice, btw.

I wanted to write in-progress tests to my code (unit tests and higher level).

I have few questions\difficulties:

  1. How high should my tests be? I know there is no "right\wrong" answer. If I write the test too high it might be difficult for me to simulate all test cases.

If I write the tests too low, every class\structural refactoring I'll do will break the tests and that would be very tedious to maintain.

I guess the solution is combining both? Or is there any best-practice guideline?

  1. How would you call tests that call the highest API of my code, when I use mocks only for out-of-process services (DB, Http service etc)? They are not unit-tests because I don't mock all dependencies?

  2. What is the best practice to inject mock using Guice in PROD code? create a mainModule class for each test-class? but then if I want a different data from the mock for each test - then I'll have as many mainModule classes as many test cases?

I could add a concrete example, but I thought the q might be cleared in general. No?

How high level should be my unit-test?

I have a program with many classes. I manage the DI with Guice, btw.

I wanted to write in-progress tests to my code (unit tests and higher level).

I have few questions\difficulties:

  1. How high should my tests be?

    I know there is no "right\wrong" answer. If I write the test too high it might be difficult for me to simulate all test cases.

    If I write the tests too low, every class\structural re-factoring I'll do will break the tests and that would be very tedious to maintain.

    I guess the solution is combining both? Or is there any best-practice guideline?

  2. How would you call tests that call the highest API of my code, when I use mocks only for out-of-process services (DB, Http service etc)? They are not unit-tests because I don't mock all dependencies?

  3. What is the best practice to inject mock using Guice in PROD code? create a mainModule class for each test-class? but then if I want a different data from the mock for each test - then I'll have as many mainModule classes as many test cases?

I could add a concrete example, but I thought the question might be cleared in general.

Source Link

how high level should be my unit-test?

I have a program with many classes. I manage the DI with Guice, btw.

I wanted to write in-progress tests to my code (unit tests and higher level).

I have few questions\difficulties:

  1. How high should my tests be? I know there is no "right\wrong" answer. If I write the test too high it might be difficult for me to simulate all test cases.

If I write the tests too low, every class\structural refactoring I'll do will break the tests and that would be very tedious to maintain.

I guess the solution is combining both? Or is there any best-practice guideline?

  1. How would you call tests that call the highest API of my code, when I use mocks only for out-of-process services (DB, Http service etc)? They are not unit-tests because I don't mock all dependencies?

  2. What is the best practice to inject mock using Guice in PROD code? create a mainModule class for each test-class? but then if I want a different data from the mock for each test - then I'll have as many mainModule classes as many test cases?

I could add a concrete example, but I thought the q might be cleared in general. No?