Coder Social home page Coder Social logo

swift-iostests-readme's Introduction

Green Lights on Learn + Xcode

Drawing

There is no greater education than one that is self-driven. -Neil deGrasse Tyson


Quick Fix

If you've come to this page over and over for info, I will include this snippet near the top (to help you out).

LOG_PATH=`echo "${BUILD_DIR}" | sed "s/Build\/Products/Logs\/Test/"`
"${SRCROOT}/test_runner.sh" "$LOG_PATH" "${SRCROOT}"

There are 3 main things to do to get lights working

1. Post-Script you need to put in Xcode
2. test_runner.sh file needs to be in the directory that contains the Xcode project
3. Run the bash command below

I think it helps to have a copy of the test_runner.sh file somewhere local on your machine that way you can keep copying and pasting the actual file over to new projects you make.

There are some labs that include tests. Learn might include an additional circle (that can be lit green) that states that you need to "Pass The Tests". When the tests pass within Xcode, the appropriate circle (on learn) should then light up green.

In order for Xcode to be able to communicate with Learn to let Learn know that all of your tests passed when completing a lab, you need to type the following command in Terminal which will install the file on your machine to make all this happen.

bash <(curl -s https://raw.githubusercontent.com/flatiron-school/ios-setup/master/install.sh)

After running the command above in terminal, you should be met with a message that states "You're all set - setup complete!" after going through any necessary steps of it asking you any questions.

completeSetup

You might notice that my terminal looks different than yours, especially that <3 icon I have.

curl https://raw.githubusercontent.com/flatiron-school/dotfiles/master/.bash_profile -o ~/.bash_profile

Typing that command in terminal will install a certain file on your machine which is setup to make your terminal application look like mine. I recommend you do this (as it's not just adding a <3 icon) but take note that by running this command it will override any customized bash_profile you might already have on your machine.

Please Note you must reload your bash profile by typing the following in terminal `source /.bash_profile


Instructions:

  • Don't create your .gitignore file yet. If you want to know why, scroll down and read the Important Note listed below.
  • Create an Xcode project. You will want it to include Unit Tests, NOT UItests.

  • You will find the test_runner.sh file included with this repo.
  • In the folder which includes YOUR Xcode project and README.md file for the current lab you're making, drag the test_runner.sh file into that folder so it ends up looking like this demo folder I made that represents a lab:

testRunner

  • If you prefer not to download the test_runner.sh file from this repo, you can create an empty test_runner.sh file within your directory and copy/paste the following information into that newly made test_runner.sh file. NOTE: This is NOT required if you dragged the file in (as suggested in the prior bullet point.)
#!/bin/bash
set -e
SERVICE_URL='http://ironbroker.flatironschool.com'
SERVICE_ENDPOINT='/e/flatiron_xcpretty'
CURR_DIR="$2"
NETRC=~/.netrc

if [ -f ${NETRC} ]; then
  if grep -q flatiron-push ${NETRC}; then
    GITHUB_USERNAME=`grep -A1 flatiron-push ${NETRC} | grep login | awk '{print $2}'`
    GITHUB_USER_ID=`grep -A2 flatiron-push ${NETRC} | grep password | awk '{print $2}'`
  else
    echo "Please run the iOS setup script before running any tests."
    exit 1
  fi
else
  echo "Please run the iOS setup script before running any tests."
  exit 1
fi

cd "$1"
gunzip -c -S .xcactivitylog `ls -t | grep 'xcactivitylog' | head -n1` | awk '{ gsub("\r", "\n"); print }' > unixfile.txt
TOTAL_COUNT=`tail -n10 unixfile.txt | grep -A1 xctest | grep Executed | awk '{print $2}'`
FAILURE_COUNT=`tail -n10 unixfile.txt | grep -A1 xctest  | grep Executed | awk '{print $5}'`
PASSING_COUNT=`echo "${TOTAL_COUNT} - ${FAILURE_COUNT}" | bc`
REPO_NAME=`echo ${CURR_DIR} | awk -F'/' '{print $NF}'`
cd ${CURR_DIR}


curl -s -H "Content-Type: application/json" -X POST --data "{ \"username\": \"${GITHUB_USERNAME}\", \"github_user_id\": \"${GITHUB_USER_ID}\", \"repo_name\": \"${REPO_NAME}\", \"build\": { \"test_suite\": [{\"framework\": \"xcpretty\", \"formatted_output\": [], \"duration\": 0.0, \"build_output\": []}]}, \"total_count\": ${TOTAL_COUNT}, \"passing_count\": ${PASSING_COUNT}, \"failure_count\": ${FAILURE_COUNT}}" "${SERVICE_URL}${SERVICE_ENDPOINT}"

  • Almost there..

sliding

Xcode Stuff:

  • Open your Xcode project file, or if using pods, open the Xcode workspace file.
  • Located at the top of Xcode (when open), to the right of the play and stop buttons, should be a button with the name of your project. In the example image below, the name of our project is LoveNotWar. If you don't see the name of your project here, click the button and a dropdown will appear that should contain your project's name. Select your project first to ensure that's the scheme with which you're working.

theRealFirst

  • Next, open the dropdown menu again and this time select "Manage Schemes..."

first

  • You should be presented with a screen that looks something like this.

second

  • Select your project's name, which is usually the top item. In this example it's "LoveNotWar". Hit "Edit..."

third

  • Expand the Test (Debug) section and select "Post-actions". These are actions taken after tests have been run in your project. Your screen should look like this:

fourth

  • You should see a + symbol in the lower left of the "No Actions" window. Select the + symbol to be presented with two options and then select "New Run Script Action".

fifth

  • Open the drop down menu where it states "Provide build settings from" and select your project.

sixth

  • Copy and paste the following lines into the text field below the drop down menu:
LOG_PATH=`echo "${BUILD_DIR}" | sed "s/Build\/Products/Logs\/Test/"`
"${SRCROOT}/test_runner.sh" "$LOG_PATH" "${SRCROOT}"

seventh

  • Close the window and run the lab's tests. All the things should now work. You did it.

congrats

Important Note!

The step where you're adding the Post-action script will not persist if you don't do this correctly.

What does that mean?

If you try to add that post-script command within your Xcode project within your directory that already contains a .gitignore file, it will NOT SAVE. You might close your Xcode, re-open it and see that it is still there, where you might shout "BUT JIM IT DID SAVE!". Yes, it saved to your local Xcode but considering your .gitignore file has this lovely line in it:

xcuserdata/

That will prevent this post-script action from being pushed up to Github. That's because any change to this post-script action (like what we did above) happens within this xcuserdata/ folder.

So there are a few ways to handle this.

  1. When you create the Xcode project for this lab, don't save it to the folder that contains the .git file (meaning the directory that you navigate to to git add ., git commit -m "" and all that jazz). Save it to your desktop, add this Post-script command to the Xcode project then drag it into the directory which contains the .git file. At that point you can enter in all those lovely git commands then push it up.
  2. Don't create the .gitignore file until you have this project created that includes the post-script action. When that post-script command is added, then git add ., git commit and then git push. At that point.. you should then create the .gitignore file.
  3. Some other magic you come up with.

If you want to make sure everything is working. Clone down the repo into a different folder somewhere, open Xcode, navigate to the post-script and make sure it's still there. If it's not there, then gitignore is ignoring it. You will need to remove the gitignore file (or just the part regarding xcuserdata/ althoug I haven't tested this out in just removing the xcuserdata/ part). Then add that post-script action to Xcode, then add, commit and push up the changes to Github. Then re-add the .gitignore file. It might still be tracking the xcuserdata info which means you will need to type git rm -rf yyyyy those xcuserdata files. yyyyy represents the name(s) of those files. You will know it's mistakenly tracking these files if you close Xcode. Type git status where you should see everything is up to date after you had added, commited and pushed the changes from the earlier step. Now re-open Xcode. Just click open a file on the left (don't add anything to it), now close xcode. If you type git status, NO files should show as being changed. If it shows a xcuserstate or data type file that needs to be commited, then that's the particular file you need to git rm -rf

Podfile

We use Quick & Nimble for tests.

Here is an example of tests written for one of our labs.

View this lesson on Learn.co

swift-iostests-readme's People

Contributors

ianrahman avatar jimcampagno avatar susanlovaglio avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

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.