Definitely Allah (swt) knows.
وَلْيَعْلَمَ الَّذِينَ نَافَقُواْ {And that He might make evident those who are hypocrites.}: In the Battle of Uhud after the defeat and that some have let down with the hypocrites, and others did not respond to the Prophet (saws) while he was calling them, so Allah is making evident those who are hypocrites for He (swt) fully knows this matter beforehand, but He (swt) linked the results with the causes, and gave the orders while left the choice to man.
Allah (swt) knows beforehand what you will choose, for He is holding you accountable for your choice, not for His knowledge; because his knowledge is from his eternal existence and of His attributes that the human mind cannot encompass no matter how long the mind goes in discovering sciences, it will not be able to know the nature of Allah (swt)’s knowledge and His wisdom, except what Allah (swt) has told us about, remembering always the words of Allah (swt):
لَيْسَ كَمِثْلِهِ شَيْءٌ
{There is nothing like unto Him.} (Ash-Shura: 11)
وَقِيلَ لَهُمْ تَعَالَوْاْ قَاتِلُواْ فِي سَبِيلِ اللّهِ أَوِ ادْفَعُواْ { For it was said to them, “Come, fight in the way of Allah or [at least] defend.”}: In the beginning, when Abdullah bin Ubayy bin Salul withdrew with a third of the army when it was said to them: Come, fight in the cause of Allah, or at least defend your homes in Medina, they said:
لَوْ نَعْلَمُ قِتَالاً لاَّتَّبَعْنَاكُمْ {If we had known [there would be] fighting, we would have followed you.”}: But since Allah (swt) knows the secret and what is even more hidden, so He brought out what is in their souls and made it clear to us as if they had said it. That is why Allah (swt) says:
يَقُولُونَ بِأَفْوَاهِهِم مَّا لَيْسَ فِي قُلُوبِهِمْ وَاللّهُ أَعْلَمُ بِمَا يَكْتُمُونَ {saying with their mouths what was not in their hearts. And Allah is most Knowing of what they conceal}.