Unit tests with NUnit

1

I just installed the "Nunit" for unit tests in my project.

I installed via Nuget on the VS2013 console.

I put the annotations on top of my methods I ran Explorer test and gave a "Run ALL".

This "Run ALL" is only compiling my project and is not showing me which tests

have passed and which failed.

NOTE: My project was already ready.

My code

using NUnit.Framework;

   [TestFixture]
    public class LogDAO
    {

        /// <summary>
        /// Metodo para inclusão 
        /// </summary>
        /// <param name="UserID"></param>
        /// <param name="Acao"></param>
        /// <returns></returns>
        [Test]
        public void InserirLog(string UserID, string Acao)
        {
            using (entidadesIUS entidades = new entidadesIUS())
            {
                LogUtilizacaoIUS log = new LogUtilizacaoIUS();
                log.UserId = new Guid(UserID);
                log.Acao = Acao;
                log.DataOcorrencia = DateTime.Now;

                entidades.LogUtilizacaoIUS.Add(log);
                entidades.SaveChanges();
            }
        }
    }
  

My test Explorer just stays that way as I said.

    
asked by anonymous 03.12.2014 / 18:16

3 answers

3

You should run the test methods in NUnit.

1- Open NUnit

In the File menu click Open Project and select the dll of your project, example YourProject.dll. The test methods, marked with [Test] , will be displayed.

3 - Select the method and click on the Run button.

It will indicate whether or not it is successful.

    
03.12.2014 / 19:28
2

I do not really know NUnit but looking at your code highlights two things:

1 - You use the [TesteCase] annotation with no parameters, so the method does not receive any values.

2 - You have declared the method InserirLog static

Make these changes:

[TestCase("valor_para _userID","Valor_para_acao")]
public void InserirLog(string UserID, string Acao)
{

Just one more note: You are not testing anything because I do not see any Assert     

03.12.2014 / 18:32
2

If you install the runner for Visual Studio 2013, the results of your tests should appear in the test explorer, without the need to open the NUnit test explorer.

Follow the link: link

Remembering that, this would be unnecessary if you used the Microsoft MSTest framework.

    
04.12.2014 / 11:08