Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Class Initialize inheritance #143 #577

Merged
merged 24 commits into from
Jul 8, 2019

Conversation

parrainc
Copy link
Contributor

@parrainc parrainc commented Mar 10, 2019

Implemented feature requested in #143

  • Create enum to handle the inheritance option in ClassInitialize attribute
  • Set None option to default in ClassInitialize attribute
  • Added properties on TestClassInfo class
  • Updated RunClassInitialize and RunClassCleanup method in TestClassInfo class
  • Updated CreateClassInfo method on TypeCache class to check for classinitialize inheritance option
  • Added a few unit tests for TestClassInfo and TypeCache

example output:
===> Init from ParentTestClass
==> Init from BaseTestClass
=> Init from DerivedTestClass

=> Cleaning up from DerivedTestClass
==> Cleaning up from BaseTestClass
===> Cleaning up from ParentTestClass

@parrainc
Copy link
Contributor Author

cc: @AbhitejJohn @jayaranigarg @singhsarab
Please, review...

@parrainc
Copy link
Contributor Author

Pushed new changes to fix that base cleanup were being called without calling base initialize

Copy link
Contributor

@AbhitejJohn AbhitejJohn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for putting this out. Added my feedback. @acesiddhu or @jayaranigarg would be able to address the framework attribute concern better but looks good overall.

src/Adapter/MSTest.CoreAdapter/Execution/TestClassInfo.cs Outdated Show resolved Hide resolved
src/Adapter/MSTest.CoreAdapter/Execution/TestClassInfo.cs Outdated Show resolved Hide resolved
src/Adapter/MSTest.CoreAdapter/Execution/TypeCache.cs Outdated Show resolved Hide resolved
src/Adapter/MSTest.CoreAdapter/Execution/TypeCache.cs Outdated Show resolved Hide resolved
src/Adapter/MSTest.CoreAdapter/Execution/TestClassInfo.cs Outdated Show resolved Hide resolved
src/Adapter/MSTest.CoreAdapter/Execution/TestClassInfo.cs Outdated Show resolved Hide resolved
src/Adapter/MSTest.CoreAdapter/Execution/TestClassInfo.cs Outdated Show resolved Hide resolved
src/Adapter/MSTest.CoreAdapter/Execution/TestClassInfo.cs Outdated Show resolved Hide resolved
src/Adapter/MSTest.CoreAdapter/Execution/TestClassInfo.cs Outdated Show resolved Hide resolved
@parrainc
Copy link
Contributor Author

@dotnet-bot test Windows / Release Build please

@sturlath
Copy link

sturlath commented Apr 9, 2019

So when can we expect this to be merged? I really need to be able to use [ClassInitialize] in my custom base class and if I'm correct this will make that possible. Right?

@parrainc
Copy link
Contributor Author

@sturlath

So when can we expect this to be merged? I really need to be able to use [ClassInitialize] in my custom base class and if I'm correct this will make that possible. Right?

From my side, I can tell you that since I've been kind of busy, i'm working a little bit slower than before on this, but even though, I think by end of next week I'll be done with this (unless there's more review to solve).

This changes will let you tell the framework to take into account your custom base class' initialize method when running your tests. So, yeah, you're correct.

I think @jayaranigarg and @AbhitejJohn could expand a bit more when this would be released after merged into master.

Copy link
Contributor

@AbhitejJohn AbhitejJohn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for updating the logic. It might need a few minor touch-ups and testing but apart from the comments I've put in, it looks good. I'm hoping @jayaranigarg or @cltshivash would be able to help with approvals and merging. I'm just helping as a fellow open source-rer and cannot merge this in myself. I can help with the cleanups if I need to, to get this in quicker.

initializeMethod = baseClassInitializeStack.Pop().Item1;
if (initializeMethod != null)
{
initializeMethod?.InvokeAsSynchronousTask(null, testContext);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do not need this null check operator here given that we are already performing a null check above.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually, i think we might needed it since the null check above is to make sure there are any non-null init method in the tuple that can be executed. In any case, I changed this for a .Where call when newing up the baseClassInitializeStack (on the this.BaseClassInitAndCleanupMethods) that way, we just pass executable init methods, and we don't need to do any extra thing to pass its corresponding cleanup method to the stack for cleanup methods to execute in the RunClassCleanup method.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like the updated code wouldn't run Cleanups from base classes that do not have an initialize method...

src/Adapter/MSTest.CoreAdapter/Execution/TestClassInfo.cs Outdated Show resolved Hide resolved
while (baseClassCleanupQueue.Count > 0)
{
classCleanupMethod = baseClassCleanupQueue.Dequeue().Item2;
classCleanupMethod?.InvokeAsSynchronousTask(null);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't we be only executing cleanups whose inits have run? This seems to be running all cleanups.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we could just push Cleanups that need to be executed into a Stack instead of ExecutedBaseClassInitializeMethods

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, I had a block of code that I removed right before pushing the latest changes, handling the logic for deciding those cleanup method that will be executed. But, now that you mentioned that last part, I think that'd be better. For that, renamed the property you mentioned, now it's called: BaseClassCleanupMethodsStack not sure if the name is 100% ok, and in the RunClassInitialize method, I'll be pushing the cleanups into that stack to then execute them in the RunClassCleanup method.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good. It doesn't look like we need a Queue here. We could just pop the methods off the stack..

@paulmccormack
Copy link

Hi

Do you know when this change will be merged and released?

Cheers

Paul

@AbhitejJohn
Copy link
Contributor

I'd like to see this in too.
/cc: @acesiddhu , @singhsarab .

@NGloreous
Copy link
Contributor

@parrainc Any updates on this change? Look like there hasn't been progress for a bit. I'm in need of this and would be happy to help if needed.

@AbhitejJohn
Copy link
Contributor

So, I've checked offline with the team on getting this in. The plan is to do the needful to merge this in early next week. I believe @parrainc has addressed most of the feedback here and I'd love to have this in the product.
/cc: @cltshivash , @jayaranigarg

@parrainc
Copy link
Contributor Author

parrainc commented Jul 2, 2019

I think most of the comments (if not, all of them) were addressed. I've been a little busy but if something still missing I could fix it, so it could be merged. So, basically, I'm waiting on @jayaranigarg @cltshivash inputs. If this looks good for them as well, then we should be good.

@jayaranigarg jayaranigarg merged commit c590c2b into microsoft:master Jul 8, 2019
@jayaranigarg
Copy link
Member

@elgatov
Copy link

elgatov commented Sep 19, 2019

@parrainc must classinitialize be static for it to run? i do not have it marked static and it will not run from a base class

@parrainc
Copy link
Contributor Author

parrainc commented Sep 30, 2019

@parrainc must classinitialize be static for it to run? i do not have it marked static and it will not run from a base class

@elgatov yes, it must has this signature:

[ClassInitialize(InheritanceBehavior.BeforeEachDerivedClass)]
public static void InitBaseClassMethod(TestContext testContext) { }

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

Successfully merging this pull request may close these issues.

7 participants