How to use gradle.properties in Junit class

I have 2 properties in gradle.properties as

Host=localhost
Port=8888

And I want to use it my Junit test.
How can I achieve this?

The gradle Test task offers a systemProperty method to create jvm system properties.
https://docs.gradle.org/current/dsl/org.gradle.api.tasks.testing.Test.html

test {
systemProperty 'host', project.host
systemProperty 'port', project.port
}

THen in your java Unit test

System.getProperty("host")

If you have tons of them, you can use

test {
systemProperties = project.properties
}

to copy all your gradle project properties to the Test Jvm system properties

test {
systemProperty ‘host’, project.host
systemProperty ‘port’, project.port
}

This is working for me.

How can I put all in one file like project.proiperties or gradle.properties and use it with systemProperties?

The following should work. See ConfigSlurper API or example
test {
systemProperties = new ConfigSlurper().parse(file('gradle.properties).toURL()).flatten()
}