Help on fixing a uri test

Sep 10, 2010 at 3:35 PM

Converting MSTests over to xunit I got one that passes under mstest but fails on xunit.

Here's the test:

public void CreatePartUriCreatesUriFromPath() {
            // Act
            Uri uri = UriHelper.CreatePartUri(@"a\b\c.txt");

            // Assert
            Assert.AreEqual(new Uri("/a/b/c.txt", UriKind.Relative), uri); 
}
It's failing on the equality of the types. Here's the failure under xunit:
C:\projects\nu\nupack>test
xUnit.net console test runner (64-bit .NET 4.0.30319.1)
Copyright (C) 2007-10 Microsoft Corporation.

xunit.dll:     Version 1.6.1.1521
Test assembly: C:\projects\nu\nupack\NuPack.Test.xUnit\bin\Debug\NuPack.Test.xUn
it\bin\Debug\NuPack.Test.xUnit.dll

NuPack.Test.xUnit.UriHelperTest.CreatePartUriCreatesUriFromPath [FAIL]
   Assert.Equal() Failure
   Expected: /a/b/c.txt (System.Uri)
   Actual:   /a/b/c.txt (System.IO.Packaging.PackUriHelper+ValidatedPartUri)
   Stack Trace:
      C:\projects\nu\nupack\NuPack.Test.xUnit\UriHelperTest.cs(15,0): at NuPack.
Test.xUnit.UriHelperTest.CreatePartUriCreatesUriFromPath()

15 total, 1 failed, 0 skipped, took 1.606 seconds

C:\projects\nu\nupack>
Thoughts?
Sep 10, 2010 at 3:46 PM
Edited Sep 10, 2010 at 3:50 PM

xunit seems to be more picky with static methods, something to watch out for in tests (but still don't have an answer to the problem above)

Sep 10, 2010 at 4:54 PM

Probably happens because Uri comparisons are tricky.  Consider the following code:

 

            Uri uri1 = new Uri("/a/b/c.txt", UriKind.Relative);
            Uri uri2 = new Uri("/a/b/c.txt", UriKind.Relative);
            Assert.IsTrue(uri1 == uri2);
            Assert.IsTrue((object)uri1 == (object)uri2);

The first assert passes and the second fails.  That's because Uri has an operator ==, and that won't get called when dealing with objects.  It's something the compiler needs to see to generate the right code.  Maybe MSTest has some extra smart to make that work.  Maybe just change the test to:

            Assert.IsTrue(new Uri("/a/b/c.txt", UriKind.Relative) == uri);

 

Developer
Sep 10, 2010 at 5:03 PM

Side question. Are you going to rename the project to NuPack.Test when it's done?

Sep 10, 2010 at 5:05 PM
That's the intent but want to leave the current project alone for now.

This message was sent via Blackberry.


From: dfowler <notifications@codeplex.com>
To: Simser, Bil
Sent: Fri Sep 10 11:03:13 2010
Subject: Re: Help on fixing a uri test [nupack:226776]

From: dfowler

Side question. Are you going to rename the project to NuPack.Test when it's done?

Developer
Sep 10, 2010 at 5:09 PM

When we move away from mstest we lose things like the integrated code coverage. We need to make sure that we have the same set of features when we move to xunit (maybe we need NCover?)

Sep 10, 2010 at 5:11 PM
NCover is commercial. Will go looking for a free and or OSS solution.

This message was sent via Blackberry.


From: dfowler <notifications@codeplex.com>
To: Simser, Bil
Sent: Fri Sep 10 11:09:44 2010
Subject: Re: Help on fixing a uri test [nupack:226776]

From: dfowler

When we move away from mstest we lose things like the integrated code coverage. We need to make sure that we have the same set of features when we move to xunit (maybe we need NCover?)

Coordinator
Sep 10, 2010 at 6:59 PM

NCover offers free licenses to OSS projects. We can consider asking them for one once we go public. But if there’s a comparable free OSS solution, I’d be happy with that too. I just haven’t found one yet.


Phil

Sep 10, 2010 at 7:12 PM

Yeah, I know they have free licenses for OSS projects. The only issue is if someone was to download the code to setup their own server I don't want them having to try to hunt down a tool. 

When I download an OSS project and the next thing is that I have to go out and buy or use some commercial tool, I just dump the OSS project. Most free copies of the license are only extended to the project team, not the users of the codebase. An RSS reader suffered from this fate (can't remember the name of it now). He used a "free" copy of Infragistics in his reader so yes, you could get the code but you couldn't use the libraries for anything but that project and since the library doesn't prevent that, all hell broke loose. No thanks. This is also one of the reasons I'd like to get off of MSTest. Nothing against it (well, okay, don't get me started on that rant) but along comes little-developer-guy who wants to setup his own system and compile it and now he needs a Professional copy of Visual Studio Test and a licensed copy of NCover and... you get the idea.

To be true to the OSS spirit, anyone should be able to build the codebase and run their own server without the need for anything except a copy of free tools that are out there. OSS projects that depend on commercial tools don't work (even ones that were given to the project).

Sep 10, 2010 at 7:41 PM

For mvccontrib and other heaspring projects I create two build targets, one that everyone can execute and a commiter target that has the additional tools, that the commiters install licenses for.  The is also dotCover from jetbrains, we could get that and use the team/city headspring oss build server.

On Sep 10, 2010 2:12 PM, "bsimser" <notifications@codeplex.com> wrote:
> From: bsimser
>
> Yeah, I know they have free licenses for OSS projects. The only issue is if someone was to download the code to setup their own server I don't want them having to try to hunt down a tool. When I download an OSS project and the next thing is that I have to go out and buy or use some commercial tool, I just dump the OSS project. Most free copies of the license are only extended to the project team, not the users of the codebase. An RSS reader suffered from this fate (can't remember the name of it now). He used a "free" copy of Infragistics in his reader so yes, you could get the code but you couldn't use the libraries for anything but that project and since the library doesn't prevent that, all hell broke loose. No thanks. This is also one of the reasons I'd like to get off of MSTest. Nothing against it (well, okay, don't get me started on that rant) but along comes little-developer-guy who wants to setup his own system and compile it and now he needs a Professional copy of Visual Studio Test and a licensed copy of NCover and... you get the idea.To be true to the OSS spirit, anyone should be able to build the codebase and run their own server without the need for anything except a copy of free tools that are out there. OSS projects that depend on commercial tools don't work (even ones that were given to the project).
>
>

Sep 10, 2010 at 8:04 PM

Yeah, that makes sense Eric and I've done in the past. So we can do that with some of the tools (because frankly most people won't care about coverage if they're running their own server).

Coordinator
Sep 10, 2010 at 10:03 PM

Yeah, exactly. I was thinking that NCover would be used by our build server primarily.

Again, if there’s a good OSS alternative out there, by all means, let’s use it and not even have to worry about having two build targets. I just haven’t found a good alternative.


Phil

Sep 11, 2010 at 1:02 AM

This thread got heavily randomized from its original purpose :)

Did you figure out the initial issue?

Sep 11, 2010 at 12:23 PM

The suggestion from davidebb fixed it. A pain that one testing framework fails while another passes on the same test. Have to wonder which one is right. And we got traction on coverage so that's a good thing.