John tells his readers to not believe everything they hear, but test the spirits (4:1a). The “spirits” in this context refers to individuals in a local church who teach or preach as they are led by the Holy Spirit.
This may be a local pastor or elder, an individual in the church, or a traveling teacher who may (or may not) be authorized by John to teach. If there were perhaps a dozen small congregations in the greater urban area of Ephesus, then John may have sent a person on a pastoral tour of the churches to deliver a message and help with any issues which the church may have had. On the other hand, the opponents may have done the same thing, so that a local church could have a visiting teacher who was not strictly orthodox from John’s perspective.
In either case, these traveling teachers would have had limited access to Scripture. It is unlikely any of these small congregations would have even small portions of the Old Testament in Greek. They may have had limited copies of some of Paul’s letters and perhaps other communiques from John. These traveling teachers would therefore rely upon the Holy Spirit to call to mind Scripture which they had memorized and their teaching was done “in the Spirit.”
It is difficult to know how these teachers functioned as Holy Spirit led preachers, but it is important to realize this may have included the gift of prophecy (properly defined as a powerful Spirit led exposition of Scripture to a current situation). But if a teacher arrived in a local church and claimed to his message was from the Holy Spirit and they had a manifestation of tongues or some ecstatic prophecy, then the local congregation might be swayed to believe them!
Testing refers to a critical examination of something in order to determine the quality of something. The verb (δοκιμάζω) can be used for testing gold, but also testing one’s character. In LXX Jer 6:27 testing gold is used as a metaphor for testing one’s character. Compare Psalm 66:10 (LXX Ps 65:10), the Lord has tested us like silver. Proverbs 17:3, the Lord tests the heart like someone might test gold and silver in a crucible. This is the sense of the verb in 1 Peter 1:7, the trials a Christian faces is like “a refiner’s fire.”
In 1 Corinthians 16:3 Paul used the word for approving men to be sent with Pau to deliver the collection of money for the poor in Jerusalem. Secular Greek might use this word for approving or ratifying a law or examining the character of a person to determine if they are worthy to hold office. In 1 Timothy 3:10 Paul tells Timothy deacons ought to be examined (tested) before they are permitted to serve as deacons. It is also the word used in 2 Tim 2:15, Timothy ought to strive to be an approved workman who has been tested.
In the context of 1 John 4, how does the church “test a spirit”? The content of any teacher ought to be examined closely in order to determine if it is from God.
In the original setting of this letter, this likely refers to the activity of a traveling preacher or teacher. Third John concerns hospitality towards traveling teachers sent out by John, it is likely the opponents have also been sending out trained teachers who might visit a church and try to sway a local community toward their theological and practical false teaching.
What is being tested? Both doctrine (what they say about Jesus) and behavior (what is the content of their character). Both are important as we apply try to find appropriate application of this teaching to contemporary church problems. There may be teachers who have good doctrine but their character is questionable (in the ministry for the money, dictatorial and abusive, etc.) But there are other teachers who have very good character but teach clear false doctrine (perhaps a very moral person, good family values, but heretical on Jesus).