Giter VIP home page Giter VIP logo

teardowngenerator's Introduction

Swift Test Tear Down Inspection for AppCode

Generating a tear down method

Motivation

For each test you write, an XCTestCase is allocated but never deallocated.

The best practice is to set all your instance variables to nil in the tear down method of your test.

This AppCode plugin inspects your tests and finds all places where one or more properties are not set to nil. It will also offer to fix the problem for you.

See the usages below on how to fix a single test file and how to apply the fix on all test files.

Installation

  • Open AppCode
  • Open AppCode → Preferences ⌘,
  • Go to Plugins
  • Click Browse repositories...
  • Search for 'Swift Test Tear Down Inspection for AppCode'
  • Click Install
  • Restart AppCode

Usages

Mid-workflow

With a Swift test file open, the class name will be highlighted with a warning if any properties are not set to nil in the tear down.

You can then ask AppCode to fix the problem for you.

  • Move the cursor to the class name
  • Press ⌥↩
  • Select 'Set properties to nil in tear down'

Batch find problems

For when you want to find all the problematic tests in the project.

  • Select Code -> Run inspection by name
  • Start typing 'Properties are not set to nil in tear down'
  • Select that inspection

Batch find and fix problems

For when you want to find and automatically fix all problematic tests in the project.

  • Select Code -> Code Cleanup
  • Select the scope.
  • Make sure the inspection is included in the Inspection Profile.
  • Click OK.

Fix problems before a commit

For when you want to automatically fix all problematic tests before a commit.

  • Select VCS -> Commit Changes
  • Stage your changes
  • Under 'Before Commit', select 'Cleanup'
  • Click Commit

teardowngenerator's People

Contributors

seanhenry avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

teardowngenerator's Issues

Continues to show yellow warning squiggly line

Sean,
First, thanks for updating this, my all-time favorite AppCode plugin! What a relief to have it back.

I'm used to the yellow warning line on the test class appearing when a class is missing a tearDown of anything in the test fixture. But in the latest version, the warning line remains after generating tearDown.

Not working in 2021.2 EAP

Intention not working.
I'm afraid I don't know my way around the JetBrains API, otherwise I'd try helping. Happy to pair with you if that helps.

java.lang.IncompatibleClassChangeError: Method 'com.jetbrains.swift.psi.SwiftPsiElementFactory com.jetbrains.swift.psi.SwiftPsiElementFactory.getInstance(com.intellij.psi.PsiElement)' must be InterfaceMethodref constant
	at codes.seanhenry.inspections.TearDownInspectionQuickFix.invoke(TearDownInspectionQuickFix.java:46)
	at com.intellij.codeInspection.LocalQuickFixOnPsiElement.applyFix(LocalQuickFixOnPsiElement.java:100)
	at com.intellij.codeInspection.LocalQuickFixOnPsiElement.applyFix(LocalQuickFixOnPsiElement.java:90)
	at com.intellij.codeInspection.LocalQuickFixOnPsiElement.applyFix(LocalQuickFixOnPsiElement.java:22)
	at com.intellij.codeInspection.actions.PerformFixesTask.collectFix(PerformFixesTask.kt:13)
	at com.intellij.codeInspection.actions.AbstractPerformFixesTask.applyFix(AbstractPerformFixesTask.java:35)
	at com.intellij.codeInspection.ex.PerformFixesModalTask.lambda$iteration$1(PerformFixesModalTask.java:100)
	at com.intellij.openapi.application.impl.ApplicationImpl.runWriteAction(ApplicationImpl.java:936)
	at com.intellij.codeInspection.ex.PerformFixesModalTask.iteration(PerformFixesModalTask.java:97)
	at com.intellij.codeInspection.ex.PerformFixesModalTask.doRun(PerformFixesModalTask.java:68)
	at com.intellij.openapi.application.impl.ApplicationImpl.lambda$runEdtProgressWriteAction$11(ApplicationImpl.java:900)
	at com.intellij.openapi.progress.impl.CoreProgressManager.lambda$runProcess$2(CoreProgressManager.java:183)
	at com.intellij.openapi.progress.impl.CoreProgressManager.registerIndicatorAndRun(CoreProgressManager.java:705)
	at com.intellij.openapi.progress.impl.CoreProgressManager.executeProcessUnderProgress(CoreProgressManager.java:647)
	at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:63)
	at com.intellij.openapi.progress.impl.CoreProgressManager.runProcess(CoreProgressManager.java:170)
	at com.intellij.openapi.progress.util.PotemkinProgress.runInSwingThread(PotemkinProgress.java:197)
	at com.intellij.openapi.application.impl.ApplicationImpl.lambda$runEdtProgressWriteAction$12(ApplicationImpl.java:900)
	at com.intellij.openapi.application.impl.ApplicationImpl.runWriteActionWithClass(ApplicationImpl.java:924)
	at com.intellij.openapi.application.impl.ApplicationImpl.runEdtProgressWriteAction(ApplicationImpl.java:898)
	at com.intellij.openapi.application.impl.ApplicationImpl.runWriteActionWithCancellableProgressInDispatchThread(ApplicationImpl.java:888)
	at com.intellij.codeInspection.actions.CleanupInspectionUtilImpl.lambda$applyFixesNoSort$0(CleanupInspectionUtilImpl.java:41)
	at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:207)
	at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:172)
	at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:162)
	at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:148)
	at com.intellij.codeInspection.actions.CleanupInspectionUtilImpl.applyFixesNoSort(CleanupInspectionUtilImpl.java:37)
	at com.intellij.codeInspection.actions.CleanupInspectionUtil.applyFixes(CleanupInspectionUtil.java:40)
	at com.intellij.codeInspection.actions.CleanupInspectionIntention.invoke(CleanupInspectionIntention.java:69)
	at com.intellij.codeInsight.intention.impl.IntentionActionWithTextCaching$MyIntentionAction.lambda$invoke$0(IntentionActionWithTextCaching.java:209)
	at com.intellij.util.SlowOperations.allowSlowOperations(SlowOperations.java:146)
	at com.intellij.codeInsight.intention.impl.IntentionActionWithTextCaching$MyIntentionAction.invoke(IntentionActionWithTextCaching.java:209)
	at com.intellij.codeInsight.intention.impl.ShowIntentionActionsHandler.invokeIntention(ShowIntentionActionsHandler.java:266)
	at com.intellij.codeInsight.intention.impl.ShowIntentionActionsHandler.lambda$chooseActionAndInvoke$3(ShowIntentionActionsHandler.java:239)
	at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:216)
	at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:172)
	at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:162)
	at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:148)
	at com.intellij.codeInsight.intention.impl.ShowIntentionActionsHandler.chooseActionAndInvoke(ShowIntentionActionsHandler.java:238)
	at com.intellij.codeInsight.intention.impl.IntentionListStep.chooseActionAndInvoke(IntentionListStep.java:134)
	at com.intellij.codeInsight.intention.impl.IntentionListStep$1.chooseActionAndInvoke(IntentionListStep.java:162)
	at com.intellij.codeInsight.intention.impl.IntentionListStep.lambda$applyAction$3(IntentionListStep.java:126)
	at com.intellij.openapi.application.TransactionGuardImpl.performUserActivity(TransactionGuardImpl.java:94)
	at com.intellij.ui.popup.AbstractPopup.lambda$dispose$18(AbstractPopup.java:1503)
	at com.intellij.util.ui.EdtInvocationManager.invokeLaterIfNeeded(EdtInvocationManager.java:101)
	at com.intellij.ide.IdeEventQueue.ifFocusEventsInTheQueue(IdeEventQueue.java:185)
	at com.intellij.ide.IdeEventQueue.executeWhenAllFocusEventsLeftTheQueue(IdeEventQueue.java:139)
	at com.intellij.openapi.wm.impl.FocusManagerImpl.doWhenFocusSettlesDown(FocusManagerImpl.java:175)
	at com.intellij.openapi.wm.impl.IdeFocusManagerImpl.doWhenFocusSettlesDown(IdeFocusManagerImpl.java:36)
	at com.intellij.ui.popup.AbstractPopup.dispose(AbstractPopup.java:1500)
	at com.intellij.ui.popup.WizardPopup.dispose(WizardPopup.java:163)
	at com.intellij.ui.popup.list.ListPopupImpl.dispose(ListPopupImpl.java:337)
	at com.intellij.openapi.util.ObjectTree.runWithTrace(ObjectTree.java:136)
	at com.intellij.openapi.util.ObjectTree.executeAll(ObjectTree.java:166)
	at com.intellij.openapi.util.Disposer.dispose(Disposer.java:155)
	at com.intellij.openapi.util.Disposer.dispose(Disposer.java:143)
	at com.intellij.ui.popup.WizardPopup.disposeAllParents(WizardPopup.java:266)
	at com.intellij.ui.popup.WizardPopup.disposeAllParents(WizardPopup.java:268)
	at com.intellij.ui.popup.list.ListPopupImpl.handleNextStep(ListPopupImpl.java:444)
	at com.intellij.ui.popup.list.ListPopupImpl._handleSelect(ListPopupImpl.java:416)
	at com.intellij.ui.popup.list.ListPopupImpl.handleSelect(ListPopupImpl.java:367)
	at com.intellij.ui.popup.list.ListPopupImpl$1.actionPerformed(ListPopupImpl.java:281)
	at com.intellij.ui.popup.WizardPopup.proceedKeyEvent(WizardPopup.java:378)
	at com.intellij.ui.popup.WizardPopup.dispatch(WizardPopup.java:354)
	at com.intellij.ui.popup.PopupDispatcher.dispatchKeyEvent(PopupDispatcher.java:112)
	at com.intellij.ui.popup.PopupDispatcher.dispatch(PopupDispatcher.java:148)
	at com.intellij.ide.IdePopupManager.dispatch(IdePopupManager.java:101)
	at com.intellij.ide.IdeEventQueue._dispatchEvent(IdeEventQueue.java:723)
	at com.intellij.ide.IdeEventQueue.lambda$dispatchEvent$7(IdeEventQueue.java:442)
	at com.intellij.openapi.progress.impl.CoreProgressManager.computePrioritized(CoreProgressManager.java:825)
	at com.intellij.ide.IdeEventQueue.lambda$dispatchEvent$8(IdeEventQueue.java:441)
	at com.intellij.openapi.application.impl.ApplicationImpl.runIntendedWriteActionOnCurrentThread(ApplicationImpl.java:794)
	at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:493)
	at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
	at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
	at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
	at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
	at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
	at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.