Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

Need guidance to run tests when using CI/CD on VSTS #549

Closed
benbuckland opened this issue Mar 21, 2018 · 8 comments
Closed

Need guidance to run tests when using CI/CD on VSTS #549

benbuckland opened this issue Mar 21, 2018 · 8 comments

Comments

@benbuckland
Copy link

benbuckland commented Mar 21, 2018

Hi there, would be great if you could provide additional guidance for testing when using VSTS for CI/CD.

So far I have built the 'unittest' container and modified the dockerfile to include:
RUN dotnet test --logger "trx;LogFileName=TEST-unittest_results.xml"
I can see the tests being run and the file being created BUT how do I know get the file in VSTS and how to stop the build if there are failing tests? I have added the 'Publish Test Results' task but it doesn't find the file. I'm guessing this is because the file is in the container vs the build environment.

I found this but cant seem to get it working (I'm guessing it is because I am using the Linux host).

Is there are more elegant way?

@eiximenis
Copy link
Contributor

Hi.
I think there is a better approach:

  1. Having a container test that saves the test results to a xml file
  2. Add the test container to compose file
  3. Create a bind mount for sharing xml results file between container and host (vsts agent)
  4. Use "docker-compose run" to run the test container. If test fails, this will make vsts build to fail (note that do not happen using docker-compose up).
  5. Use the "publish test results" task to publish test results to vsts. Configure task to run even though previous task fails.

[A bit of spam]: I wrote a blog post in my blog (in spanish) about the topic: https://geeks.ms/etomas/2018/03/07/ejecutar-pruebas-de-tus-contenedores-en-vsts/ It is centered on a simpler case (only one container) but is easily extensible to multi-container solution like eShop.

Anyway @CESARDELATORRE maybe we could create some wiki topic for this issue

@benbuckland
Copy link
Author

@eiximenis thanks for this, this approach makes sense. I am quite new to Docker, can you give me some rough pointers as to what I will need to alter from your example in order to make it work with a multi-container solution?

@NicolasReyDotNet
Copy link

NicolasReyDotNet commented Mar 23, 2018

I've just asked the exact same question here
https://forums.asp.net/p/2138254/6198514.aspx?p=True&t=636573940055548684

Any guidance available somewhere for microservices ?

@NicolasReyDotNet
Copy link

@eiximenis
Your article is brillant, congratz!!

It's exactly what I was looking for, but with no luck on Google.

I just have an additional question about Microservices : should each Microservice project have its own Test project ? Indeed in eShopOnContainer it's not the case and I wonder how you deal with your tests in VSTS ??
This a very important point that we can't find any reliable guidance anywhere.

@NicolasReyDotNet
Copy link

NicolasReyDotNet commented Mar 27, 2018

@eiximenis I tried to leave a comment on your blog with no success.
I encounter a problem on the Publish Task following your tutorial : VSTS is not able to find the test result xml file (problem described here)
Could you advice me ? I can't find a full explanatory tutorial about the CI part on dotnet with Docker especially when using Unit Tests....
Thanks

@eiximenis
Copy link
Contributor

Hi @NicolasReyDotNet
I answered your comment in my blog (I was on holidays so I did not saw your comments).
I copy here the same comment I left as my asnwer:

The VSTS pipeline I have is exactly the one shown in this article.
The key point is the bind mount between the test container and the host (the VSTS build agent). Just be sure that you have the volume defined (either in docker-compose.yml as in my post or in docker-compose.override.yml file) and be sure that the path of the bind mount is correct.

In VSTS I use th BUILD_ARTIFACTSTAGINGDIRECTORY environment variable as a host path for the bind mount, so in the “Publish Test Result Task” I need to set the “Search folder” to Search folder: $(Build.ArtifactStagingDirectory)

Let me know if you still have problems!

@NicolasReyDotNet
Copy link

@eiximenis
Thanks for your feedback (hope your holidays were good !)

I can't access your blog since I posted a comment, I get a blank screen : same from each device from where I posted a comment (sorry for the double post I thought an error occured)
Blank screen on blog

Well, I stilll get the same problem... I think I should miss some point, but I don't know which one.
Is it possible to continue this discussion on stackoverflow ( ?to not pollute the original issue with my needs) ? 'm really sorry to bother you but you're the first one who achieved my exact needs with a fully understandable article ...

The discussion on stackverflow is here CI publish test fail

@mvelosop
Copy link
Collaborator

mvelosop commented Jun 26, 2018

Closing this issue.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants