there are a couple ways i do (i think they are kinda unorthodox tho) whenever i learn a lick i test it out over various types of chords. I have my friend play a chord and i play the lick and just listen to how it sounds. You could also write out the notes in the lick and then depending on the number of sharps or flats you could find the key (if you understand the circle of fifths) sometimes licks have a few outside notes. not all licks are going to fit into a certain key. i recomend just listening when you play it. Keys and scales to me are just suggestions, you just gotta listen and have fun with it.