Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Manually associated test fixture with dependent class
DanielM
#1 Posted : Tuesday, October 31, 2017 4:07:55 AM(UTC)
Rank: Newbie

Groups: Registered
Joined: 2/13/2017(UTC)
Posts: 9
Location: United States of America

Was thanked: 2 time(s) in 2 post(s)
Hello,

We have NCrunch configured to re-run tests automatically when changes are detected. This works great for large projects with lots of tests. I discovered that I have an issue similar to the one suggested here http://forum.ncrunch.net...--files-with-tests.aspx I didn't see how to contribute to that thread so I'm starting this one. In my case I'm using the DevExpress POCO MVVM framework and with this framework you are able to define metadata classes for your view models. Then you can associated the metadata class to your view model via an attribute like the example below. The issue I'm having is that when I define validation rules in the metadata class, NCrunch doesn't see the association and the validation tests (or any other test dependent on the metadata code) become out of sync / incorrect (passing/failing when they shouldn't). I found manually rebuilding/running the tests get the unit tests state back in sync but this is a bit awkward and not very effective. Is there anyway to tell my test fixture class to rerun tests whenever my metadata class changes?

[POCOViewModel]
[MetadataType(typeof(MyViewModelMetadata))]
public MyViewModel {}

Thanks so much
Daniel
Remco
#2 Posted : Tuesday, October 31, 2017 4:13:24 AM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 6,976

Thanks: 930 times
Was thanked: 1257 time(s) in 1170 post(s)
Hi Daniel,

Thanks for posting.

Just to clarify, are you talking about the 'Run impacted tests automatically, others manually' mode? (The run all tests automatically runs everything regardless of impact detection).

Can you share any more details around how the metadata classes are utilised by your code under test? In most scenarios, I would expect the impact detection to trigger on changes made to these classes if they are containing code that is physically covered by the tests.
DanielM
#3 Posted : Tuesday, October 31, 2017 4:46:27 AM(UTC)
Rank: Newbie

Groups: Registered
Joined: 2/13/2017(UTC)
Posts: 9
Location: United States of America

Was thanked: 2 time(s) in 2 post(s)
Hi Remco,

Thanks for the speedy reply! Yes, I'm referring to the 'Run impacted tests automatically, others manually' mode. That is handy as we have 10's of thousands of tests and running them all is time consuming and just isn't necessary .... but it does help to warm my office in the winter months ;)

I triple checked just now and you're are right... The tests were in sync with the state of the code and I modified the metadata class and NCrunch rightfully picked up on the changes and ran only the impacted tests (and the results were correct). For whatever reason this wasn't the case earlier today... and then I remember at one point I was using an extension method to group and reuse common validation rules (like below). I played with modifying the extension method and the test results remained in sync....

If anything comes to mind as to what may have happened let me know ...but otherwise it looks like it's working as expected again. I'll just keep an eye out for it try to pin it down better next time. What's odd is I even did a 'resync, rebuild, and run all' earlier today and the issues remained.

public MyViewModelMetadata
{
public override void BuildMetadata(MetadataBuilder<MyViewModel> builder)
{
builder.Property(x => x.Total).CannotBeNegativeAndShouldNotBeZero();
}
}

... then in an extensions class I have the method

public static void CannotBeNegativeOrZero<T, TProperty>(this PropertyMetadataBuilder<T, TProperty> builder)
where TProperty : IComparable
{
builder.MatchesRule(x => !x.Equals(0.00), () => "{0} cannot be zero.").MatchesRule(x => Convert.ToDouble(x) > 0.00, () => "{0} cannot be negative.");
}
Remco
#4 Posted : Tuesday, October 31, 2017 10:27:51 AM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 6,976

Thanks: 930 times
Was thanked: 1257 time(s) in 1170 post(s)
I have a feeling that you may have discovered a hole in the impact detection. Probably you made a change to a code structure in a way that the impact detection couldn't detect, so nothing was run.

If it's happened to you once, it'll likely happen again. If you can identify the hole and discover a way to reproduce it, I'll have a good chance of being able to fix it for you.
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

YAF | YAF © 2003-2011, Yet Another Forum.NET
This page was generated in 0.036 seconds.
Trial NCrunch
Take NCrunch for a spin
Do your fingers a favour and supercharge your testing workflow
Free Download