Select id from apexclass where class name like '%test%'.
Above query if fetching both managed and unmanaged package classes, can i filter only unmanaged package.
You can filter by the namespace prefix. Assuming your org is not a developer org:
SELECT Id FROM ApexClass WHERE NamespacePrefix = NULL AND Name LIKE '%Test%'
Alternatively, I prefer to use SOSL, so I don't accidentally pick up files that have Test in the name but are not actual tests:
FIND '@isTest' IN ALL FIELDS RETURNING ApexClass(Id WHERE NamespacePrefix = NULL)