views:

147

answers:

3

I've included the necessary assemblies into a Windows Class project in VS2008. When I start to try to write a test I get a red squiggle line and the message [Test] is not a valid attribute. I've used NUnit before... maybe an earlier version. What am I doing wrong? I'm on version 2.5.2.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit;
using NUnit.Core;
using NUnit.Framework;

namespace MyNamespace
{
    public class LoginTests
    {
        [Test]
        public void CanLogin()
        {
        }
    }
}
A: 

Hi, You are missing the [TestFixture] attribute on top of your class, also, you only need to include the following usings for NUnit: using NUnit.Framework;

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;

namespace MyNamespace
{
    [TestFixture]
    public class LoginTests
    {
        [Test]
        public void CanLogin()
        {
        }
    }
}
Riaan
No, this is not the cause of error.
Anton Gogolev
I agree. [TestFixture] won't allow me to use it without parameters. Never seen that before. But I think I read somewhere that it was no longer needed for simple test classes. But I can't figure out the [Test] problem.
tyndall
+4  A: 

It is the extra using lines getting you in trouble. Only use using NUnit.Framework;

Internally NUnit.Core also has a type named Test and you are colliding with that.

Altenatively you could use [TestAttribute] fully spelling out the Attribute part resolves the collision.

Mike Two
Thanks a combo of this ... and dropping and adding my references seemed to resolve the issue.
tyndall
@tyndall - glad it helped. Sorry, I should have been more explicit about dropping the reference to NUnit.Core. You shouldn't need it for normal test writing.
Mike Two
+2  A: 

I had a similar problem to this using version 2.5.3. The problem was that I was looking for the dll files in the "lib" directory of my nunit installation when I should have been looking in the "framework" directory. So when I referenced the "framework\nunit.framework.dll" dll everything worked. Hope this helps

Anonymous
This answer was spot on for my part - referencing from the framework dir solved the problem
Hauge