0

today i set up a new ms build project in jenkins which contains unit tests and integration tests. Before i moved the project to jenkins, i used my local machine to run the tests (Nunit, Reshaper).

Some of my integration tests uses databases to test some logic and i configured the database file location as a static property that is used in my tests to establish a database connection.

As you can imagine this was a little problem when i moved the project to jenkins, because i did not have the database files at the same location.

To solve the problem right now i changed some SetUp() methods in my integration tests. They load a folder from a textfile and this folder points to a resource path where all my needed files are stored. Now i can run the tests on jenkins and my local machine.

I have a bad feeling about this, it feels not correct some how. What would you do to solve my problem? Mocking the files is no solution, i want to interact with the files.

Thank you!

2 Answers 2

1

Generally, I think, it is not a good idea to take anything from files during running unit tests. Especially it is not a good idea to take anything from txt/xml/etc files which, as you suppose, will be copied to debug folder. Different unit test engines behave differently, some of them have shadow copy option and some of them might have this option switched on by default. Shadow copy will make it almost impossible to locate non-dll files in original Debug folder.

I would recommend embedding all the data you need into the test assembly. Two ways to do it:

  1. Hardcode test data as a string in some class. Then write it to the file or consume it directly.
  2. Add files as resources which will be embedded into test assembly.
1
  • 1
    Thank you for your answer. my problem appears in an application that is used to synchronize multiple source databases into one destination database - i totally agree with you that interacting with files in unit test is no good idea, but this is about integration testing. i broke down the tests to be 90% unit test and 10% integration. and the real Problem about embedding the files into a resource File is: even a empty database has a 80mb size (700 tables with lot of fields). would you still reccomend your solution with this additional information?
    – Grrbrr404
    Nov 29, 2011 at 15:48
1

What about adding the test data file to your source control system and also to the .net project. Then configure them that they should be copied into the 'out' dir and you can access them in unit test since they will be copied into that folder by msbuild.

2
  • Shadow copy will bring you troubles with such an approach.
    – Snowbear
    Nov 29, 2011 at 14:27
  • Pls see my comment at snowbears answer - items somehow Trier for your answer
    – Grrbrr404
    Nov 29, 2011 at 15:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.