Question 1:
I would say if you want to do TDD, then this is not the "right" way, because, as you said, you will perform integration tests. Again, perhaps you do not want to do TDD, and the integration tests are good enough for you, but to answer the question: this will not be the right way ** unit - ** to check your code.
Question 2
I would say that it depends on what you have at your level of data access. For example, if you are implementing repositories, you probably want to write some tests.
Save method
You want to make sure that, provided that the object that you extracted from your repository has edited some properties of this object and saved the changes, it will actually save the changes and will not create a new object. Now: you might think that this is an integration test, but it really depends on how well your code is designed. For example, your repository might just be an extra layer of logic on top of a low-level ORM. In this case, when testing the save method, what you will do is that you will argue that the correct methods are called with the correct parameters in the ORM service entered into your repository.
Errors and Exceptions
There may be problems accessing the data, such as connecting to a broken database, or the data format is not as expected, or problems of deserialization. If you want to ensure good error handling and possibly create custom exceptions and add additional information to them depending on the context, then you definitely want to write tests to make sure that the correction information is distributed
, on the other hand
If your DAL is just a few classes that wrap the unthinkable ORM and you donβt have any logic there, then you probably donβt need tests, but it seems like this does not happen too often, you will almost always have some logic, which may go wrong and what you want to test.
source share