A very exciting start saw the hosts open up the scoring with a penalty after six minutes. However, Connacht scrum half Paul O'Donohoe responded quickly by touching down for the game's first try just four minutes later.
His half-back partner Dan Parks added the extras but from rom the restart, Connacht conceded a penalty which resulted in a Castres try from a rolling maul which they converted.
Once again, Conacht did not waste any time in fighting back and replied immediately with some great phase play leading to a try in the corner by 24-year-old winger Matt Healy. Parks missed the conversion but Connacht were two points in front.
Less than 10 minutes later, Healy was celebrating his second try of the game. Great pressure from centre Eoin Griffin allowed Healy to run in from about 40 metres out, beating three Castres players on the way. Connacht missed the conversion.
Just before half-time, Castres scored a try against the run of play and converted to get back level at 17 points apiece. A late first half penalty put them three points ahead (20-17) going into the dressing rooms.
An entirely new Connacht team was brought on for the second half as was planned by head coach Lam. Castres made their own changes as well, notably brining on British & Irish Lions lock Richie Gray.
The French side started the second period well with a try in the corner, converted to leave them 10 points ahead.
Connacht's number 8 and second half captain John Muldoon worked a try from a five-metre lineout which was followed by a successful conversion from the boot of Miah Nikora to further close the gap.
Two Castres tries, one converted, follow shortly while Connacht had a try of their own disallowed for a double movement.
The closing stages of the game saw the visitors pile on the pressure and a great breakout from the 22 by Fionn Carr led to a penalty just five metres from the Castres line. Replacement scrum half Kieran Marmion took a quick tap and dived in to score under the posts.
Number 10 Craig Ronaldson, who was making his frst appearance in a Connacht jersey, added the conversion just before the final whistle.
Ronan Loughney, JP Cooney, James Rael, Ronaldson and Marmion were all given game-time as replacements.
Giving his assessment of Connacht's first pre-season outing, Lam said: "I'm really proud of the boys. A lot of them were playing their first game for the team this evening. We saw some really good stuff out there, scoring five tries, and we probably left another four or five out there.
"Overall, to give the majority of the squad a run-out was extremely pleasing. There were a lot of positives but we have a lot to work on and the real key is that the guys know there are areas we can improve on.
"So onwards and upwards, we move on to Wasps and another tough week of training next week."
Connacht play London Wasps at home at the Sportsground next Saturday at 5pm. Tickets are available online at tickets.ie and from the Connacht Rugby office. All Season Ticket holders are granted free entry to the pre-season game.
CONNACHT (first half team v Castres): Gavin Duffy (capt); Steve Macauley *, Eoin Griffin, Conor Finn *, Matt Healy; Dan Parks, Paul O'Donohoe; Peter Reilly *, Jason Harris-Wright, Nathan White, Aly Muldowney *, Daniel Qualter, Mata Fifita, Willie Faloon, George Naoupu.
CONNACHT (second half team): Shane Layden; Tiernan O'Halloran, Danie Poolman, Brian Murphy, Fionn Carr; Miah Nikora, Marcus Walsh *; Brett Wilkinson, Sean Henry *, Rodney Ah You, Michael Kearney, Conor Kindregan *, Andrew Browne, Jake Heenan *, John Muldoon (capt).
Replacements (second half): Ronan Loughney, JP Cooney, James Rael *, Kieran Marmion, Craig Ronaldson *.
* Denotes uncapped player