Firstly keep alert, so that when you perceive that a sinful intention appears, it is quenched at its inception before it gains any momentum.

Genesis 4:7
7 If you do well, will not your countenance be lifted up? And if you do not do well, sin is crouching at the door; and its desire is for you, but you must master it.”

1 Peter 5:8
8 Be of sober spirit, be on the alert. Your adversary, the devil, prowls around like a roaring lion, seeking someone to devour.

When this intention doesn't leave, but turns into a test, remember that whatever it is, God does not give us burdens beyond what we can bear and He always provides the way out:

1 Corinthians 10:13
13 No temptation has overtaken you but such as is common to man; and God is faithful, who will not allow you to be tempted beyond what you are able, but with the temptation will provide the way of escape also, so that you will be able to endure it.

It's our own lust that entices us, but we are blessed if we persevere:

James 1:12-15
12 Blessed is a man who perseveres under trial; for once he has been approved, he will receive the crown of life which the Lord has promised to those who love Him. 13 Let no one say when he is tempted, “I am being tempted by God”; for God cannot be tempted by evil, and He Himself does not tempt anyone. 14 But each one is tempted when he is carried away and enticed by his own lust.15 Then when lust has conceived, it gives birth to sin; and when sin is accomplished, it brings forth death.

This is how we persevere and fight:

Our armour:

Ephesians 6:10-17
10 Finally, be strong in the Lord and in the strength of His might. 11 Put on the full armor of God, so that you will be able to stand firm against the schemes of the devil. 12 For our struggle is not against flesh and blood, but against the rulers, against the powers, against the world forces of this darkness, against the spiritual forces of wickedness in the heavenly places. 13 Therefore, take up the full armor of God, so that you will be able to resist in the evil day, and having done everything, to stand firm. 14 Stand firm therefore, having girded your loins with truth, and having put on the breastplate of righteousness, 15 and having shod your feet with the preparation of the gospel of peace; 16 in addition to all, taking up the shield of faith with which you will be able to extinguish all the flaming arrows of the evil one. 17 And take the helmet of salvation, and the sword of the Spirit, which is the word of God.

God is our shield, if only we allow Him to be:

Psalm 3:3
But You, O Lord, are a shield about me,
My glory, and the One who lifts my head.

God is with us and it's us who reject Him when we fall, not the other way round:

Psalm27:1
27 The Lord is my light and my salvation;
Whom shall I fear?
The Lord is the defense of my life;
Whom shall I dread?

Romans 8:31
31 What then shall we say to these things? If God is for us, who is against us?

Often we have to show perseverance when tested and wait for God's deliverance, because it may not come immediately. Eventually, however, it always comes:

Psalm 27:14
14 Wait for the Lord;
Be strong and let your heart take courage;
Yes, wait for the Lord.

Psalm 130:5-6
5 I wait for the Lord, my soul does wait,
And in His word do I hope.
6 My soul waits for the Lord
More than the watchmen for the morning;
Indeed, more than the watchmen for the morning.

It is a sobering thing to remember that nothing is hidden from God. Our thoughts, words and deeds are also a testimony before those who observe us:

Psalm 94:9
9 He who planted the ear, does He not hear?
He who formed the eye, does He not see?

Proverbs 5:21
21 For the ways of a man are before the eyes of the Lord,
And He watches all his paths.

Psalm 33:13-14
13 The Lord looks from heaven;
He sees all the sons of men;
14 From His dwelling place He looks out
On all the inhabitants of the earth,

Hebrews 4:13
13 And there is no creature hidden from His sight, but all things are open and laid bare to the eyes of Him with whom we have to do.

Even if under the test we are about to give up on ourselves, let's persevere for the sake of those who observe us and can draw encouragement from our testimony:

Hebrews 12:1-2
12 Therefore, since we have so great a cloud of witnesses surrounding us, let us also lay aside every encumbrance and the sin which so easily entangles us, and let us run with endurance the race that is set before us, 2 fixing our eyes on Jesus, the author and perfecter of faith, who for the joy set before Him endured the cross, despising the shame, and has sat down at the right hand of the throne of God.

And there are always witnesses around us. Angels watch us, even if at a particular time no other person does:

1 Corinthians 4:9
9 For, I think, God has exhibited us apostles last of all, as men condemned to death; because we have become a spectacle to the world, both to angels and to men.
Completing the test and not giving in to sin is the evidence of our faith for which we will be rewarded when our Lord comes:

1 Peter 1:6-7
6 In this you greatly rejoice, even though now for a little while, if necessary, you have been distressed by various trials, 7 so that the proof of your faith, being more precious than gold which is perishable, even though tested by fire, may be found to result in praise and glory and honor at the revelation of Jesus Christ;

Our Lord will reward us according to our deeds:

Revelation 22:12
12 “Behold, I am coming quickly, and My reward is with Me, to render to every man according to what he has done.

All these difficulties we now face daily cannot be compared to what awaits us:

Romans 8:18
18 For I consider that the sufferings of this present time are not worthy to be compared with the glory that is to be revealed to us.

The words of our Lord state the matter clearly and leave no room for middle ground:

Luke 6:46
46 “Why do you call Me, ‘Lord, Lord,’ and do not do what I say?

Matthew 16:24
24 Then Jesus said to His disciples, “If anyone wishes to come after Me, he must deny himself, and take up his cross and follow Me.”

Inevitably, however, we all sin. When we do, we need to confess in genuine repentance. David's penitential psalms - 51, 32, 130, 143 – can help us in the prayer of confession.

1 John 1:9-10
8 If we say that we have no sin, we are deceiving ourselves and the truth is not in us. 9 If we confess our sins, He is faithful and righteous to forgive us our sins and to cleanse us from all unrighteousness. 10 If we say that we have not sinned, we make Him a liar and His word is not in us.

1 John 2:1-2
2 My little children, I am writing these things to you so that you may not sin. And if anyone sins, we have an Advocate with the Father, Jesus Christ the righteous; 2 and He Himself is the propitiation for our sins; and not for ours only, but also for those of the whole world.

Once we have confessed our sins to God, let's start again without dwelling on the failure, which has now been forgiven based on the sacrifice of our Lord.

Philippians 3:13-14
13 Brethren, I do not regard myself as having laid hold of it yet; but one thing I do: forgetting what lies behind and reaching forward to what lies ahead, 14 I press on toward the goal for the prize of the upward call of God in Christ Jesus.