How to programmatically edit iPhone accessibility settings during unit test?How to programmatically send SMS on the iPhone?How should I unit test threaded code?How can I develop for iPhone using a Windows development machine?How do I test a private function or a class that has private methods, fields or inner classes?Unit Testing C CodeIs Unit Testing worth the effort?Unit test naming best practicesJavaScript unit test tools for TDDWhat is Unit test, Integration Test, Smoke test, Regression Test?How can I make a UITextField move up when the keyboard is present - on starting to edit?

Which verb form to use with "с"

Should developer taking test phones home or put in office?

Are there any vegetarian astronauts?

Can ADFS connect to other SSO services?

Should I include salary information on my CV?

Abel-Jacobi map on symmetric product of genus 4 curve

C-152 carb heat on before landing in hot weather?

Require advice on power conservation for backpacking trip

Is adding a new player (or players) a DM decision, or a group decision?

Cascading Repair Costs following Blown Head Gasket on a 2004 Subaru Outback

Employer wants to use my work email account after I quit, is this legal under German law? Is this a GDPR waiver?

Using “sparkling” as a diminutive of “spark” in a poem

Could Sauron have read Tom Bombadil's mind if Tom had held the Palantir?

Does squid ink pasta bleed?

Does the posterior necessarily follow the same conditional dependence structure as the prior?

Should my manager be aware of private LinkedIn approaches I receive? How to politely have this happen?

Unusual mail headers, evidence of an attempted attack. Have I been pwned?

Story-based adventure with functions and relationships

Impossible darts scores

What happens when I sacrifice a creature when my Teysa Karlov is on the battlefield?

STM Microcontroller burns every time

Why do some professors with PhDs leave their professorships to teach high school?

Is it damaging to turn off a small fridge for two days every week?

Analog is Obtuse!



How to programmatically edit iPhone accessibility settings during unit test?


How to programmatically send SMS on the iPhone?How should I unit test threaded code?How can I develop for iPhone using a Windows development machine?How do I test a private function or a class that has private methods, fields or inner classes?Unit Testing C CodeIs Unit Testing worth the effort?Unit test naming best practicesJavaScript unit test tools for TDDWhat is Unit test, Integration Test, Smoke test, Regression Test?How can I make a UITextField move up when the keyboard is present - on starting to edit?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








1















My application supports dynamic fonts. When user changes font size in settings (Settings > General > Accessibility > Larger Text) and jump back to application then every label should be updated.



It is implemented by overriding UILabel's function



override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) 
super.traitCollectionDidChange(previousTraitCollection)
guard previousTraitCollection?.preferredContentSizeCategory != traitCollection.preferredContentSizeCategory else return

let metrics: UIFontMetrics = UIFontMetrics(
forTextStyle: UIFont.TextStyle.body
)
font = metrics.scaledFont(for: font)



Now I need to test if other views react correctly to label's dynamic nature.



Specifically, I would like to have following unit test:



  1. Create view with label

  2. Get size of view

  3. Change system font to bigger

  4. Get size of view

  5. Compare if sizes changed

func testDynamicFont() 

let v: MyView = MyView()
let oldSize: CGSize = v.intrinsicContentSize
??? What to do here? ???
let newSize: CGSize = v.intrinsicContentSize
XCTAssertNotEqual(
oldSize,
newSize,
"Size of view should adjust to new environment"
)










share|improve this question
























  • Does the below answer solves your problem?

    – Anand
    Mar 26 at 15:12











  • Yes it do. Thank you :)

    – Pikacz
    Mar 26 at 16:12

















1















My application supports dynamic fonts. When user changes font size in settings (Settings > General > Accessibility > Larger Text) and jump back to application then every label should be updated.



It is implemented by overriding UILabel's function



override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) 
super.traitCollectionDidChange(previousTraitCollection)
guard previousTraitCollection?.preferredContentSizeCategory != traitCollection.preferredContentSizeCategory else return

let metrics: UIFontMetrics = UIFontMetrics(
forTextStyle: UIFont.TextStyle.body
)
font = metrics.scaledFont(for: font)



Now I need to test if other views react correctly to label's dynamic nature.



Specifically, I would like to have following unit test:



  1. Create view with label

  2. Get size of view

  3. Change system font to bigger

  4. Get size of view

  5. Compare if sizes changed

func testDynamicFont() 

let v: MyView = MyView()
let oldSize: CGSize = v.intrinsicContentSize
??? What to do here? ???
let newSize: CGSize = v.intrinsicContentSize
XCTAssertNotEqual(
oldSize,
newSize,
"Size of view should adjust to new environment"
)










share|improve this question
























  • Does the below answer solves your problem?

    – Anand
    Mar 26 at 15:12











  • Yes it do. Thank you :)

    – Pikacz
    Mar 26 at 16:12













1












1








1








My application supports dynamic fonts. When user changes font size in settings (Settings > General > Accessibility > Larger Text) and jump back to application then every label should be updated.



It is implemented by overriding UILabel's function



override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) 
super.traitCollectionDidChange(previousTraitCollection)
guard previousTraitCollection?.preferredContentSizeCategory != traitCollection.preferredContentSizeCategory else return

let metrics: UIFontMetrics = UIFontMetrics(
forTextStyle: UIFont.TextStyle.body
)
font = metrics.scaledFont(for: font)



Now I need to test if other views react correctly to label's dynamic nature.



Specifically, I would like to have following unit test:



  1. Create view with label

  2. Get size of view

  3. Change system font to bigger

  4. Get size of view

  5. Compare if sizes changed

func testDynamicFont() 

let v: MyView = MyView()
let oldSize: CGSize = v.intrinsicContentSize
??? What to do here? ???
let newSize: CGSize = v.intrinsicContentSize
XCTAssertNotEqual(
oldSize,
newSize,
"Size of view should adjust to new environment"
)










share|improve this question
















My application supports dynamic fonts. When user changes font size in settings (Settings > General > Accessibility > Larger Text) and jump back to application then every label should be updated.



It is implemented by overriding UILabel's function



override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) 
super.traitCollectionDidChange(previousTraitCollection)
guard previousTraitCollection?.preferredContentSizeCategory != traitCollection.preferredContentSizeCategory else return

let metrics: UIFontMetrics = UIFontMetrics(
forTextStyle: UIFont.TextStyle.body
)
font = metrics.scaledFont(for: font)



Now I need to test if other views react correctly to label's dynamic nature.



Specifically, I would like to have following unit test:



  1. Create view with label

  2. Get size of view

  3. Change system font to bigger

  4. Get size of view

  5. Compare if sizes changed

func testDynamicFont() 

let v: MyView = MyView()
let oldSize: CGSize = v.intrinsicContentSize
??? What to do here? ???
let newSize: CGSize = v.intrinsicContentSize
XCTAssertNotEqual(
oldSize,
newSize,
"Size of view should adjust to new environment"
)







ios swift unit-testing






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 26 at 9:51









sourav.bh

4441 gold badge5 silver badges19 bronze badges




4441 gold badge5 silver badges19 bronze badges










asked Mar 25 at 10:31









PikaczPikacz

531 silver badge8 bronze badges




531 silver badge8 bronze badges












  • Does the below answer solves your problem?

    – Anand
    Mar 26 at 15:12











  • Yes it do. Thank you :)

    – Pikacz
    Mar 26 at 16:12

















  • Does the below answer solves your problem?

    – Anand
    Mar 26 at 15:12











  • Yes it do. Thank you :)

    – Pikacz
    Mar 26 at 16:12
















Does the below answer solves your problem?

– Anand
Mar 26 at 15:12





Does the below answer solves your problem?

– Anand
Mar 26 at 15:12













Yes it do. Thank you :)

– Pikacz
Mar 26 at 16:12





Yes it do. Thank you :)

– Pikacz
Mar 26 at 16:12












1 Answer
1






active

oldest

votes


















1














You can increase the System Font size using below code.



 let settings = XCUIApplication(bundleIdentifier: "com.apple.Preferences")
settings.launch()
settings.tables.staticTexts["General"].tap()
settings.tables.staticTexts["Accessibility"].tap()
settings.tables.staticTexts["Larger Text"].tap()
settings.sliders.element.adjust(toNormalizedSliderPosition: 0.7) // Increase as you need


To go back to your own app,



let yourapp = XCUIApplication(bundleIdentifier: "com.xxx.yourappbundleid")
yourapp.activate()


Tested in iPhone (Real Device), iOS 12.1.4






share|improve this answer



























    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55335786%2fhow-to-programmatically-edit-iphone-accessibility-settings-during-unit-test%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    You can increase the System Font size using below code.



     let settings = XCUIApplication(bundleIdentifier: "com.apple.Preferences")
    settings.launch()
    settings.tables.staticTexts["General"].tap()
    settings.tables.staticTexts["Accessibility"].tap()
    settings.tables.staticTexts["Larger Text"].tap()
    settings.sliders.element.adjust(toNormalizedSliderPosition: 0.7) // Increase as you need


    To go back to your own app,



    let yourapp = XCUIApplication(bundleIdentifier: "com.xxx.yourappbundleid")
    yourapp.activate()


    Tested in iPhone (Real Device), iOS 12.1.4






    share|improve this answer





























      1














      You can increase the System Font size using below code.



       let settings = XCUIApplication(bundleIdentifier: "com.apple.Preferences")
      settings.launch()
      settings.tables.staticTexts["General"].tap()
      settings.tables.staticTexts["Accessibility"].tap()
      settings.tables.staticTexts["Larger Text"].tap()
      settings.sliders.element.adjust(toNormalizedSliderPosition: 0.7) // Increase as you need


      To go back to your own app,



      let yourapp = XCUIApplication(bundleIdentifier: "com.xxx.yourappbundleid")
      yourapp.activate()


      Tested in iPhone (Real Device), iOS 12.1.4






      share|improve this answer



























        1












        1








        1







        You can increase the System Font size using below code.



         let settings = XCUIApplication(bundleIdentifier: "com.apple.Preferences")
        settings.launch()
        settings.tables.staticTexts["General"].tap()
        settings.tables.staticTexts["Accessibility"].tap()
        settings.tables.staticTexts["Larger Text"].tap()
        settings.sliders.element.adjust(toNormalizedSliderPosition: 0.7) // Increase as you need


        To go back to your own app,



        let yourapp = XCUIApplication(bundleIdentifier: "com.xxx.yourappbundleid")
        yourapp.activate()


        Tested in iPhone (Real Device), iOS 12.1.4






        share|improve this answer















        You can increase the System Font size using below code.



         let settings = XCUIApplication(bundleIdentifier: "com.apple.Preferences")
        settings.launch()
        settings.tables.staticTexts["General"].tap()
        settings.tables.staticTexts["Accessibility"].tap()
        settings.tables.staticTexts["Larger Text"].tap()
        settings.sliders.element.adjust(toNormalizedSliderPosition: 0.7) // Increase as you need


        To go back to your own app,



        let yourapp = XCUIApplication(bundleIdentifier: "com.xxx.yourappbundleid")
        yourapp.activate()


        Tested in iPhone (Real Device), iOS 12.1.4







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Mar 26 at 15:11

























        answered Mar 25 at 16:06









        AnandAnand

        1,13712 silver badges20 bronze badges




        1,13712 silver badges20 bronze badges





























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55335786%2fhow-to-programmatically-edit-iphone-accessibility-settings-during-unit-test%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

            Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

            Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript